diff --git a/platform/preferred_languages.cpp b/platform/preferred_languages.cpp index 7b26271865..a6982956f8 100644 --- a/platform/preferred_languages.cpp +++ b/platform/preferred_languages.cpp @@ -172,4 +172,27 @@ string GetCurrentNorm() return Normalize(GetCurrentOrig()); } +string GetCurrentTwine() +{ + string const lang = GetCurrentOrig(); + // Special cases for different Chinese variations. + if (lang.find("zh") == 0) + { + string lower = lang; + strings::AsciiToLower(lower); + + // Traditional Chinese. + for (char const * s : {"hant", "tw", "hk", "mo"}) + { + if (lower.find(s) != string::npos) + return "zh-Hant"; + } + + // Simplified Chinese by default for all other cases. + return "zh-Hans"; + } + // Use short 2-chars versions for all other languages. + return Normalize(lang); } + +} // namespace languages diff --git a/platform/preferred_languages.hpp b/platform/preferred_languages.hpp index 557febe048..679a9eb75f 100644 --- a/platform/preferred_languages.hpp +++ b/platform/preferred_languages.hpp @@ -5,7 +5,7 @@ namespace languages { -/// @note This functions are heavy enough to call them often. Be careful. +/// @note These functions are heavy enough to call them often. Be careful. //@{ /// @return List of original system languages in the form "en-US|ru-RU|es|zh-Hant". @@ -14,6 +14,9 @@ string GetPreferred(); /// @return Original language code for the current user in the form "en-US", "zh-Hant". string GetCurrentOrig(); +/// @return Current language in out Twine translations compatible format, e.g. "en", "pt" or "zh-Hant". +string GetCurrentTwine(); + /// @return Normalized language code for the current user in the form "en", "zh". //@{ /// Returned languages are normalized to our supported languages in the core, see multilang_utf8_string.cpp