diff --git a/desktop_version/src/CWrappers.cpp b/desktop_version/src/CWrappers.cpp index 959ed707..1458a0c8 100644 --- a/desktop_version/src/CWrappers.cpp +++ b/desktop_version/src/CWrappers.cpp @@ -5,12 +5,12 @@ #include "Localization.h" #include "UtilityClass.h" -char* HELP_number_words(int _t) +char* HELP_number_words(int _t, const char* number_class) { /* C wrapper for UtilityClass::number_words. * Caller must VVV_free. */ - std::string str = help.number_words(_t); + std::string str = help.number_words(_t, number_class); char* buffer = (char*) SDL_malloc(str.size() + 1); str.copy(buffer, str.size()); diff --git a/desktop_version/src/CWrappers.h b/desktop_version/src/CWrappers.h index d1aad758..a1681c7f 100644 --- a/desktop_version/src/CWrappers.h +++ b/desktop_version/src/CWrappers.h @@ -7,7 +7,7 @@ extern "C" { #endif /* __cplusplus */ -char* HELP_number_words(int _t); +char* HELP_number_words(int _t, const char* number_class); uint32_t LOC_toupper_ch(uint32_t ch); #ifdef __cplusplus diff --git a/desktop_version/src/Localization.cpp b/desktop_version/src/Localization.cpp index 9ebce28c..150d620c 100644 --- a/desktop_version/src/Localization.cpp +++ b/desktop_version/src/Localization.cpp @@ -125,18 +125,28 @@ void gettext_plural_fill(char* buf, size_t buf_len, const char* eng_plural, cons va_end(args); } -std::string getnumber(int n) +std::string getnumber(int n, const char* number_class) { if (n < 0 || n > 100) { return help.String(n); } - if (number[n].empty()) + // FIXME: implement a more flexible system later, where translators define the classes + std::string (*number_ptr)[101]; + if (SDL_strcmp(number_class, "wordy2") == 0) + { + number_ptr = &number2; + } + else + { + number_ptr = &number; + } + if ((*number_ptr)[n].empty()) { return help.String(n); } - return number[n]; + return (*number_ptr)[n]; } static bool is_script_custom(const char* script_id) diff --git a/desktop_version/src/Localization.h b/desktop_version/src/Localization.h index 399400c7..1f5c3bbf 100644 --- a/desktop_version/src/Localization.h +++ b/desktop_version/src/Localization.h @@ -82,7 +82,7 @@ const char* gettext(const char* eng); const char* gettext_case(const char* eng, char textcase); const char* gettext_plural(const char* eng_plural, const char* eng_singular, int count); void gettext_plural_fill(char* buf, size_t buf_len, const char* eng_plural, const char* eng_singular, const char* args_index, ...); -std::string getnumber(int n); +std::string getnumber(int n, const char* number_class); const TextboxFormat* gettext_cutscene(const std::string& script_id, const std::string& eng, char textcase); const char* get_roomname_explanation(bool custom_level, int roomx, int roomy); const char* get_roomname_translation(bool custom_level, int roomx, int roomy); diff --git a/desktop_version/src/LocalizationStorage.cpp b/desktop_version/src/LocalizationStorage.cpp index a670a995..08bbc2b1 100644 --- a/desktop_version/src/LocalizationStorage.cpp +++ b/desktop_version/src/LocalizationStorage.cpp @@ -240,6 +240,7 @@ void resettext(bool final_shutdown) for (size_t i = 0; i <= 100; i++) { number[i] = ""; + number2[i] = ""; } SDL_zeroa(number_plural_form); number_plural_form[1] = 1; @@ -743,6 +744,14 @@ static void loadtext_numbers(void) number[value] = std::string(tra); tally_untranslated(tra, &n_untranslated[UNTRANSLATED_NUMBERS]); + + // FIXME: implement a more flexible system later, where translators define the classes + tra = pElem->Attribute("translation2"); + if (tra == NULL) + { + tra = ""; + } + number2[value] = std::string(tra); } if (value >= 0 && value <= 199) { diff --git a/desktop_version/src/LocalizationStorage.h b/desktop_version/src/LocalizationStorage.h index 5d9172e5..e7b42391 100644 --- a/desktop_version/src/LocalizationStorage.h +++ b/desktop_version/src/LocalizationStorage.h @@ -27,6 +27,7 @@ namespace loc LS_INTERN hashmap* map_translation; LS_INTERN hashmap* map_translation_plural; LS_INTERN std::string number[101]; /* 0..100 */ + LS_INTERN std::string number2[101]; /* 0..100 */ LS_INTERN unsigned char number_plural_form[200]; /* [0..99] for 0..99, [100..199] for *00..*99 */ LS_INTERN hashmap* map_translation_cutscene; LS_INTERN hashmap* map_translation_cutscene_custom; diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index a2442230..64766733 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -173,11 +173,11 @@ std::string UtilityClass::timestring( int t ) return output; } -std::string UtilityClass::number_words( int _t ) +std::string UtilityClass::number_words(int _t, const char* number_class) { if (loc::lang != "en") { - return loc::getnumber(_t); + return loc::getnumber(_t, number_class); } static const std::string ones_place[] = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; diff --git a/desktop_version/src/UtilityClass.h b/desktop_version/src/UtilityClass.h index 9543861d..586dd2d2 100644 --- a/desktop_version/src/UtilityClass.h +++ b/desktop_version/src/UtilityClass.h @@ -107,7 +107,7 @@ public: std::string timestring(int t); - std::string number_words(int _t); + std::string number_words(int _t, const char* number_class); static bool intersects( SDL_Rect A, SDL_Rect B ); diff --git a/desktop_version/src/VFormat.c b/desktop_version/src/VFormat.c index 81fd1aaf..09bef427 100644 --- a/desktop_version/src/VFormat.c +++ b/desktop_version/src/VFormat.c @@ -151,6 +151,7 @@ void vformat_cb_valist( size_t name_len = 0; bool flag_wordy = false; + bool flag_wordy2 = false; int flag_digits = 0; bool flag_spaces = false; bool flag_upper = false; @@ -185,6 +186,10 @@ void vformat_cb_valist( { flag_wordy = true; } + else if (flag_len == 6 && SDL_memcmp(cursor, "wordy2", 6) == 0) + { + flag_wordy2 = true; + } else if (flag_len >= 8 && SDL_memcmp(cursor, "digits=", 7) == 0) { /* strtol stops on the first non-digit anyway, so... */ @@ -253,9 +258,9 @@ void vformat_cb_valist( if (match) { - if (flag_wordy) + if (flag_wordy || flag_wordy2) { - char* number = HELP_number_words(value); + char* number = HELP_number_words(value, flag_wordy2 ? "wordy2" : "wordy"); if (flag_upper) { call_with_upper(callback, userdata, number, SDL_strlen(number));