diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/language.h | 2 | ||||
-rw-r--r-- | src/settings_gui.cpp | 2 | ||||
-rw-r--r-- | src/strings.cpp | 36 | ||||
-rw-r--r-- | src/strings_func.h | 1 |
4 files changed, 22 insertions, 19 deletions
diff --git a/src/language.h b/src/language.h index 884ac4540..84e9fa9b9 100644 --- a/src/language.h +++ b/src/language.h @@ -59,4 +59,6 @@ struct LanguageMetadata : public LanguagePackHeader { /** The currently loaded language. */ extern const LanguageMetadata *_current_language; +bool ReadLanguagePack(const LanguageMetadata *lang); + #endif /* LANGUAGE_H */ diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 871a3b8ea..24f73bd71 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -418,7 +418,7 @@ struct GameOptionsWindow : Window { break; case GOW_LANG_DROPDOWN: // Change interface language - ReadLanguagePack(index); + ReadLanguagePack(&_dynlang.ent[index]); CheckForMissingGlyphsInLoadedLanguagePack(); UpdateAllVirtCoords(); ReInitAllWindows(); diff --git a/src/strings.cpp b/src/strings.cpp index 06565064d..04d8e296e 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1323,11 +1323,11 @@ bool LanguagePackHeader::IsValid() const StrValid(this->digit_decimal_separator, lastof(this->digit_decimal_separator)); } -bool ReadLanguagePack(int lang_index) +bool ReadLanguagePack(const LanguageMetadata *lang) { /* Current language pack */ size_t len; - LanguagePack *lang_pack = (LanguagePack *)ReadFileToMem(_dynlang.ent[lang_index].file, &len, 200000); + LanguagePack *lang_pack = (LanguagePack *)ReadFileToMem(lang->file, &len, 200000); if (lang_pack == NULL) return false; /* End of read data (+ terminating zero added in ReadFileToMem()) */ @@ -1385,7 +1385,7 @@ bool ReadLanguagePack(int lang_index) free(_langpack_offs); _langpack_offs = langpack_offs; - _current_language = &_dynlang.ent[lang_index]; + _current_language = lang; _current_text_dir = (TextDirection)_current_language->text_dir; const char *c_file = strrchr(_current_language->file, PATHSEPCHAR) + 1; strecpy(_config_language_file, c_file, lastof(_config_language_file)); @@ -1538,33 +1538,35 @@ void InitializeLanguagePacks() const char *lang = GetCurrentLocale("LC_MESSAGES"); if (lang == NULL) lang = "en_GB"; - int chosen_language = -1; ///< Matching the language in the configuartion file or the current locale - int language_fallback = -1; ///< Using pt_PT for pt_BR locale when pt_BR is not available - int en_GB_fallback = 0; ///< Fallback when no locale-matching language has been found + const LanguageMetadata *chosen_language = NULL; ///< Matching the language in the configuartion file or the current locale + const LanguageMetadata *language_fallback = NULL; ///< Using pt_PT for pt_BR locale when pt_BR is not available + const LanguageMetadata *en_GB_fallback = _dynlang.ent; ///< Fallback when no locale-matching language has been found _dynlang.num = language_count; /* Fill the dynamic languages structures */ for (uint i = 0; i < language_count; i++) { + const LanguageMetadata *lng = &_dynlang.ent[i]; /* We are trying to find a default language. The priority is by * configuration file, local environment and last, if nothing found, - * english. If def equals -1, we have not picked a default language */ - const char *lang_file = strrchr(_dynlang.ent[i].file, PATHSEPCHAR) + 1; - if (strcmp(lang_file, _config_language_file) == 0) chosen_language = i; - - if (chosen_language == -1) { - if (strcmp (_dynlang.ent[i].isocode, "en_GB") == 0) en_GB_fallback = i; - if (strncmp(_dynlang.ent[i].isocode, lang, 5) == 0) chosen_language = i; - if (strncmp(_dynlang.ent[i].isocode, lang, 2) == 0) language_fallback = i; + * english. */ + const char *lang_file = strrchr(lang, PATHSEPCHAR) + 1; + if (strcmp(lang_file, _config_language_file) == 0) { + chosen_language = lng; + break; } + + if (strcmp (lng->isocode, "en_GB") == 0) en_GB_fallback = lng; + if (strncmp(lng->isocode, lang, 5) == 0) chosen_language = lng; + if (strncmp(lng->isocode, lang, 2) == 0) language_fallback = lng; } /* We haven't found the language in the config nor the one in the locale. * Now we set it to one of the fallback languages */ - if (chosen_language == -1) { - chosen_language = (language_fallback != -1) ? language_fallback : en_GB_fallback; + if (chosen_language == NULL) { + chosen_language = (language_fallback != NULL) ? language_fallback : en_GB_fallback; } - if (!ReadLanguagePack(chosen_language)) usererror("Can't read language pack '%s'", _dynlang.ent[chosen_language].file); + if (!ReadLanguagePack(chosen_language)) usererror("Can't read language pack '%s'", chosen_language->file); } /** diff --git a/src/strings_func.h b/src/strings_func.h index 6d7e5dc33..22c1f35d9 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -98,7 +98,6 @@ static inline void CopyOutDParam(uint64 *dst, int offs, int num) extern DynamicLanguages _dynlang; // defined in strings.cpp extern TextDirection _current_text_dir; ///< Text direction of the currently selected language -bool ReadLanguagePack(int index); void InitializeLanguagePacks(); const char *GetCurrentLanguageIsoCode(); |