Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2016-02-25 17:38:31 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:49:30 +0300
commit2dd4c4c38a767507bd5f822df8233ce678a749a2 (patch)
tree09cc39c127238bd20df82ac6143db0b6b7a4d9f5 /platform
parent011ca81098074880462905ded6e3c4a5c50ba255 (diff)
languages::GetCurrentTwine() returns language in our twine translations compatible format.
Diffstat (limited to 'platform')
-rw-r--r--platform/preferred_languages.cpp23
-rw-r--r--platform/preferred_languages.hpp5
2 files changed, 27 insertions, 1 deletions
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