From 37222c3fa2f558df5f7ef420ad583ba403ceda62 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 11 Apr 2021 17:28:47 +0200 Subject: [PATCH] Change: treat languages as finished, if translations are 75% completed. Unfinished translations are not auto-picked from the locale. In release builds, unfinished translations are not offered in the GUI. Unfinished translations are available in non-release builds, or by editing openttd.cfg. --- src/language.h | 1 + src/settings_gui.cpp | 2 ++ src/strings.cpp | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/src/language.h b/src/language.h index faac595613..9d2499068b 100644 --- a/src/language.h +++ b/src/language.h @@ -58,6 +58,7 @@ struct LanguagePackHeader { char cases[MAX_NUM_CASES][CASE_GENDER_LEN]; ///< the cases used by this translation bool IsValid() const; + bool IsReasonablyFinished() const; /** * Get the index for the given gender. diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 1e3bdb7d7d..f5872c648f 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -218,6 +218,8 @@ struct GameOptionsWindow : Window { case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown for (uint i = 0; i < _languages.size(); i++) { + bool hide_language = IsReleasedVersion() && !_languages[i].IsReasonablyFinished(); + if (hide_language) continue; bool hide_percentage = IsReleasedVersion() || _languages[i].missing < _settings_client.gui.missing_strings_threshold; auto item = new DropDownListParamStringItem(hide_percentage ? STR_JUST_RAW_STRING : STR_GAME_OPTIONS_LANGUAGE_PERCENTAGE, i, false); if (&_languages[i] == _current_language) { diff --git a/src/strings.cpp b/src/strings.cpp index aeea7c071a..d533db1fce 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1716,6 +1716,15 @@ bool LanguagePackHeader::IsValid() const StrValid(this->digit_decimal_separator, lastof(this->digit_decimal_separator)); } +/** + * Check whether a translation is sufficiently finished to offer it to the public. + */ +bool LanguagePackHeader::IsReasonablyFinished() const +{ + /* "Less than 25% missing" is "sufficiently finished". */ + return 4 * this->missing < LANGUAGE_TOTAL_STRINGS; +} + /** * Read a particular language. * @param lang The metadata about the language. @@ -1969,6 +1978,10 @@ void InitializeLanguagePacks() } if (strcmp (lng.isocode, "en_GB") == 0) en_GB_fallback = &lng; + + /* Only auto-pick finished translations */ + if (!lng.IsReasonablyFinished()) continue; + if (strncmp(lng.isocode, lang, 5) == 0) chosen_language = &lng; if (strncmp(lng.isocode, lang, 2) == 0) language_fallback = &lng; }