a9de10547a
* Adds a key to toggle the language to English and back on the fly Adds a Keybind called "Toggle language to English", default assigned to the key "," for testing purposes. If from the game options a language different from english was selected when using this key, when pressing this button the language will toggle between the two. * fixed formatting * small formatting fix Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * small formatting fix Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * small formatting fix Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Improved readability * small formatting fix Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * by default the keybind is now unbound * made the change_language code into it's own function previously changing language was tied to whatever other things set_language() was doing, so that functionality has been taken out so that other code can access it. * added const + format fix * added const * improved naming of functions The previously called "set_language()" became "set_language_from_options()" to better portray what it did. The new function that allows to change language from code got the previously occupied name of set_language as "set_language(const std::string &lang)" * Allows "Toggle language to en" to work in every menu * Added .empty() checks for safety * Changed to compare actions instead of strings * using references instead of making copies * Item text inside inventory tab gets correctly refreshed * astyle format * now the action is not registered to a specific contest, should be global * fix comment and spacing * Invalidate all ui_adaptors after changing language * initialized undefined variable * Correctly regenerate cache for item descriptions in the crafting menu when language is changed * moved lang_version variable inside recipe_result_info_cache * Makes inventory_item_menu refresh when the language change I've moved the code drawing that menu inside an if() statement inside the loop so we can check after every input if the language was changed and a redraw is needed. Because of, I've had to pull up some variable outside of the if() scope so that they could continue to be visible to the switch below that needs them. * Toggle now also work in the Compare menu Similar commit to the previous one, moved the rendering code into an if() statement inside the loop so that it can be checked after every input. Then moved the variables that need to be visible at a higher scope outside of the loop * central portion of the crafting menu was still cached - fixed I had missed the central part of crafting menu being cached * implemented suggestions * Apply suggestions from code review Co-authored-by: Jianxiang Wang (王健翔) <qrox@sina.com> * moved variable closed to where it's used * added missing update of a bool * moved variable outside of loop * moved variable outside of loop Had to move some variables outside of the loop, because in the case of "item_info_first" and second, if they got deleted at each iteration of the loop could cause exceptions, in the case of "scroll_pos" the position of the scrollbar need to be maintained. "page_size" as well shouldn't be reset at each iteration of the loop. * added comment * update cache for the right portion of the building screen * added comment * added comment * fixed comment - * empty commit * empty commit --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Jianxiang Wang (王健翔) <qrox@sina.com>
92 lines
3.3 KiB
C++
92 lines
3.3 KiB
C++
#include <iosfwd>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "cata_catch.h"
|
|
#include "translations.h"
|
|
|
|
// wrapping in another macro to prevent collection of the test string for translation
|
|
#ifndef TRANSLATE_MACRO
|
|
#define TRANSLATE_MACRO(msg) _( msg )
|
|
#endif
|
|
|
|
// wrapping in another macro to prevent collection of the test string for translation
|
|
#ifndef TRANSLATE_TRANSLATION
|
|
#define TRANSLATE_TRANSLATION(msg) to_translation( msg ).translated()
|
|
#endif
|
|
|
|
TEST_CASE( "translations_sanity_test", "[translations]" )
|
|
{
|
|
const std::string test_string = "__untranslated_test_string__";
|
|
|
|
CHECK( TRANSLATE_MACRO( test_string ) == test_string );
|
|
CHECK( TRANSLATE_TRANSLATION( test_string ) == test_string );
|
|
}
|
|
|
|
// assuming [en] language is used for this test
|
|
// test should succeed both with and without the LOCALIZE
|
|
TEST_CASE( "translations_macro_string_stability", "[translations]" )
|
|
{
|
|
std::vector<std::string> test_strings;
|
|
|
|
SECTION( "untranslated strings" ) {
|
|
test_strings = { "__untranslated_string1__", "__untranslated_string2__" };
|
|
}
|
|
|
|
SECTION( "translated strings" ) {
|
|
test_strings = { "thread", "yarn" };
|
|
}
|
|
|
|
std::string test_arg;
|
|
//note: this TRANSLATE_MACRO called in different iterations of the `for` loop will have
|
|
// the same static cache
|
|
for( const std::string &test_string : test_strings ) {
|
|
test_arg.assign( test_string );
|
|
// translation result should be assignable to the `const std::string &` local variable
|
|
const std::string &res1 = TRANSLATE_MACRO( test_arg );
|
|
CHECK( res1 == test_string );
|
|
}
|
|
}
|
|
|
|
// assuming [en] language is used for this test
|
|
// test should succeed both with and without the LOCALIZE
|
|
TEST_CASE( "translations_macro_char_address", "[translations]" )
|
|
{
|
|
SECTION( "address should be same when translation is absent" ) {
|
|
const char *test_string = "__untranslated_string1__";
|
|
CHECK( TRANSLATE_MACRO( test_string ) == test_string );
|
|
}
|
|
|
|
SECTION( "current address of the arg should be returned when translation is absent" ) {
|
|
// wrapped in lambda to ensure that different calls hit the same internal cache
|
|
const auto translate = []( const char *msg ) {
|
|
return TRANSLATE_MACRO( msg );
|
|
};
|
|
|
|
// same content, different address (std::string is used to ensure that)
|
|
const std::string test_string1 = "__untranslated_string1__";
|
|
const std::string test_string2 = "__untranslated_string1__";
|
|
// address should be different!
|
|
REQUIRE( test_string1.c_str() != test_string2.c_str() );
|
|
// note: address comparison is intended
|
|
CHECK( translate( test_string1.c_str() ) == test_string1.c_str() );
|
|
CHECK( translate( test_string2.c_str() ) == test_string2.c_str() );
|
|
CHECK( translate( test_string1.c_str() ) == test_string1.c_str() );
|
|
}
|
|
}
|
|
|
|
#ifdef LOCALIZE
|
|
// this test will only succeed when LOCALIZE is enabled
|
|
// assuming [en] language is used for this test
|
|
// requires .mo file for "en" language
|
|
TEST_CASE( "translations_macro_char_address_translated", "[.][translations]" )
|
|
{
|
|
set_language_from_options();
|
|
// translated string
|
|
const char *test_string = "thread";
|
|
|
|
// should return a stable address of translation that is different from the argument
|
|
CHECK( TRANSLATE_MACRO( test_string ) != test_string );
|
|
}
|
|
#endif
|