From 75d343293f4fbadb7bc9da3450b0aa51c5b21e6b Mon Sep 17 00:00:00 2001 From: Dunedan Date: Thu, 20 Feb 2025 16:17:15 +0100 Subject: [PATCH] Remove "useLongStrings" logic As it turns out we don't need that special logic for handling the "long" locale properly and everything continues to work as before without it. The only difference is that the number format not being the one from en_us anymore when using the "long" locale, but the one of the system-wide configured language, which should be an even better user experience than before. --- .../data/mods/public/gui/locale/locale.js | 12 +---- source/i18n/L10n.cpp | 44 +++---------------- source/i18n/L10n.h | 17 ------- source/i18n/scripting/JSInterface_L10n.cpp | 1 - 4 files changed, 9 insertions(+), 65 deletions(-) diff --git a/binaries/data/mods/public/gui/locale/locale.js b/binaries/data/mods/public/gui/locale/locale.js index f03094c2e9..7e4ba9bbb8 100644 --- a/binaries/data/mods/public/gui/locale/locale.js +++ b/binaries/data/mods/public/gui/locale/locale.js @@ -6,21 +6,13 @@ function init() var currentLocale = Engine.GetCurrentLocale(); var currentLocaleDictName = Engine.GetFallbackToAvailableDictLocale(currentLocale); - var useLongStrings = Engine.UseLongStrings(); - var index = -1; - if (useLongStrings) - index = languageList.list_data.indexOf("long"); - if (index == -1) - index = languageList.list_data.indexOf(currentLocaleDictName); + var index = languageList.list_data.indexOf(currentLocaleDictName); if (index != -1) languageList.selected = index; var localeText = Engine.GetGUIObjectByName("localeText"); - if (useLongStrings) - localeText.caption = "long"; - else - localeText.caption = currentLocale; + localeText.caption = currentLocale; } function cancelSetup() diff --git a/source/i18n/L10n.cpp b/source/i18n/L10n.cpp index 1de646cb08..c6c14dcfcf 100644 --- a/source/i18n/L10n.cpp +++ b/source/i18n/L10n.cpp @@ -170,11 +170,6 @@ const icu::Locale& L10n::GetCurrentLocale() const bool L10n::SaveLocale(const std::string& localeCode) const { - if (localeCode == "long" && InDevelopmentCopy()) - { - g_ConfigDB.SetValueString(CFG_USER, "locale", "long"); - return true; - } return SaveLocale(icu::Locale(icu::Locale::createCanonical(localeCode.c_str()))); } @@ -290,19 +285,9 @@ void L10n::ReevaluateCurrentLocaleAndReload() std::string locale; CFG_GET_VAL("locale", locale); - if (locale == "long") - { - // Set ICU to en_US to have a valid language for displaying dates - m_CurrentLocale = icu::Locale::getUS(); - m_CurrentLocaleIsOriginalGameLocale = false; - m_UseLongStrings = true; - } - else - { - GetDictionaryLocale(locale, m_CurrentLocale); - m_CurrentLocaleIsOriginalGameLocale = (m_CurrentLocale == icu::Locale::getUS()) == 1; - m_UseLongStrings = false; - } + GetDictionaryLocale(locale, m_CurrentLocale); + m_CurrentLocaleIsOriginalGameLocale = (m_CurrentLocale == icu::Locale::getUS()) == 1; + LoadDictionaryForCurrentLocale(); } @@ -318,11 +303,6 @@ std::vector L10n::GetAllLocales() const } -bool L10n::UseLongStrings() const -{ - return m_UseLongStrings; -}; - std::vector L10n::GetSupportedLocaleBaseNames() const { std::vector supportedLocaleCodes; @@ -532,8 +512,6 @@ Status L10n::ReloadChangedFile(const VfsPath& path) return INFO::OK; std::wstring dictName = GetFallbackToAvailableDictLocale(m_CurrentLocale); - if (m_UseLongStrings) - dictName = L"long"; if (dictName.empty()) return INFO::OK; @@ -564,19 +542,11 @@ void L10n::LoadDictionaryForCurrentLocale() m_Dictionary = std::make_unique(); VfsPaths filenames; - if (m_UseLongStrings) + std::wstring dictName = GetFallbackToAvailableDictLocale(m_CurrentLocale); + if (vfs::GetPathnames(g_VFS, L"l10n/", dictName.append(L".*.po").c_str(), filenames) < 0) { - if (vfs::GetPathnames(g_VFS, L"l10n/", L"long.*.po", filenames) < 0) - return; - } - else - { - std::wstring dictName = GetFallbackToAvailableDictLocale(m_CurrentLocale); - if (vfs::GetPathnames(g_VFS, L"l10n/", dictName.append(L".*.po").c_str(), filenames) < 0) - { - LOGERROR("No files for the dictionary found, but at this point the input should already be validated!"); - return; - } + LOGERROR("No files for the dictionary found, but at this point the input should already be validated!"); + return; } for (const VfsPath& path : filenames) diff --git a/source/i18n/L10n.h b/source/i18n/L10n.h index e9c37d522a..9f25546408 100644 --- a/source/i18n/L10n.h +++ b/source/i18n/L10n.h @@ -210,15 +210,6 @@ public: */ std::string GetLocaleScript(const std::string& locale) const; - /** - * Returns @c true if the current locale is the special "Long Strings" - * locale. It returns @c false otherwise. - * - * @return Whether the current locale is the special "Long Strings" - * (@c true) or not (@c false). - */ - bool UseLongStrings() const; - /** * Returns an array of paths to files in the virtual filesystem that provide * translations for the specified locale code. @@ -523,14 +514,6 @@ private: */ bool m_CurrentLocaleIsOriginalGameLocale{false}; - /** - * Whether the game is using the special game locale with the longest - * strings of each translation (@c true) or not (@c false). - * - * @sa https://gitea.wildfiregames.com/0ad/0ad/wiki/Implementation_of_Internationalization_and_Localization#LongStringsLocale - */ - bool m_UseLongStrings{false}; - /** * Loads the translation files for the * @link L10n::GetCurrentLocale() current locale@endlink. diff --git a/source/i18n/scripting/JSInterface_L10n.cpp b/source/i18n/scripting/JSInterface_L10n.cpp index cfea5f2560..657de7d4fa 100644 --- a/source/i18n/scripting/JSInterface_L10n.cpp +++ b/source/i18n/scripting/JSInterface_L10n.cpp @@ -84,7 +84,6 @@ void RegisterScriptFunctions(const ScriptRequest& rq) REGISTER_L10N_FUNC(static_cast(&L10n::GetDictionaryLocale), "GetDictionaryLocale"); REGISTER_L10N(GetDictionariesForLocale) - REGISTER_L10N(UseLongStrings) REGISTER_L10N(GetLocaleLanguage) REGISTER_L10N(GetLocaleBaseName) REGISTER_L10N(GetLocaleCountry)