From 953bf0335ec95a04f757301c957554823123cee0 Mon Sep 17 00:00:00 2001 From: Sergey Pisarchik Date: Wed, 21 May 2014 22:31:18 +0300 Subject: [PATCH] [Tizen] Rename tizen_string_utils to tizen_utils. Add CodeFromISO369_2to_1 function. --- platform/http_thread_tizen.cpp | 2 +- platform/platform.pro | 4 +- platform/platform_tizen.cpp | 2 +- platform/preferred_languages.cpp | 6 +- platform/tizen_string_utils.cpp | 27 -- platform/tizen_utils.cpp | 256 ++++++++++++++++++ ...tizen_string_utils.hpp => tizen_utils.hpp} | 2 + tizen/MapsWithMe/src/AboutForm.cpp | 2 +- tizen/MapsWithMe/src/FormFactory.cpp | 2 +- tizen/MapsWithMe/src/MapsWithMeForm.cpp | 2 +- 10 files changed, 267 insertions(+), 38 deletions(-) delete mode 100644 platform/tizen_string_utils.cpp create mode 100644 platform/tizen_utils.cpp rename platform/{tizen_string_utils.hpp => tizen_utils.hpp} (76%) diff --git a/platform/http_thread_tizen.cpp b/platform/http_thread_tizen.cpp index 8bf0406468..ea2b9a510b 100644 --- a/platform/http_thread_tizen.cpp +++ b/platform/http_thread_tizen.cpp @@ -3,7 +3,7 @@ #include "platform.hpp" #include "http_thread_callback.hpp" -#include "tizen_string_utils.hpp" +#include "tizen_utils.hpp" #include diff --git a/platform/platform.pro b/platform/platform.pro index 8739a15896..4437ec4c46 100644 --- a/platform/platform.pro +++ b/platform/platform.pro @@ -41,10 +41,10 @@ INCLUDEPATH += $$ROOT_DIR/3party/jansson/src SOURCES += platform_android.cpp \ pthread_video_timer.cpp } else:tizen* { - HEADERS += tizen_string_utils.hpp \ + HEADERS += tizen_utils.hpp \ http_thread_tizen.hpp SOURCES += platform_tizen.cpp \ - tizen_string_utils.cpp \ + tizen_utils.cpp \ pthread_video_timer.cpp \ http_thread_tizen.cpp \ } diff --git a/platform/platform_tizen.cpp b/platform/platform_tizen.cpp index e70c619eb5..b0cb4db90d 100644 --- a/platform/platform_tizen.cpp +++ b/platform/platform_tizen.cpp @@ -12,7 +12,7 @@ #include "constants.hpp" #include "platform_unix_impl.hpp" -#include "tizen_string_utils.hpp" +#include "tizen_utils.hpp" #include "http_thread_tizen.hpp" #include diff --git a/platform/preferred_languages.cpp b/platform/preferred_languages.cpp index 3abd13def0..3d47c31cda 100644 --- a/platform/preferred_languages.cpp +++ b/platform/preferred_languages.cpp @@ -24,8 +24,7 @@ string GetAndroidSystemLanguage(); #elif defined(OMIM_OS_TIZEN) -// @TODO - + #include "tizen_utils.hpp" #else #error "Define language preferences for your platform" @@ -174,8 +173,7 @@ void SystemPreferredLanguages(vector & languages) languages.push_back(GetAndroidSystemLanguage()); #elif defined(OMIM_OS_TIZEN) -// @TODO - + languages.push_back(GetTizenLocale()); #else #error "Define language preferences for your platform" #endif diff --git a/platform/tizen_string_utils.cpp b/platform/tizen_string_utils.cpp deleted file mode 100644 index 6e24d42bb5..0000000000 --- a/platform/tizen_string_utils.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "tizen_string_utils.hpp" -#include "../../std/vector.hpp" - -#include "../../tizen/inc/FBase.hpp" - - -string FromTizenString(Tizen::Base::String const & str_tizen) -{ - string utf8Str; - if (str_tizen.GetLength() == 0) - return utf8Str; - Tizen::Base::ByteBuffer * pBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(str_tizen); - if (pBuffer) - { - int byteCount = pBuffer->GetLimit(); - - byteCount--; // Don't copy Zero at the end - if (byteCount > 0) - { - vector chBuf(byteCount); - pBuffer->GetArray((byte *)&chBuf[0], 0, byteCount); - utf8Str.assign(chBuf.begin(), chBuf.end()); - } - delete pBuffer; - } - return utf8Str; -} diff --git a/platform/tizen_utils.cpp b/platform/tizen_utils.cpp new file mode 100644 index 0000000000..bc47e68aef --- /dev/null +++ b/platform/tizen_utils.cpp @@ -0,0 +1,256 @@ +#include "tizen_utils.hpp" +#include "../../std/vector.hpp" + +#include "../../tizen/inc/FBase.hpp" +#include "../base/logging.hpp" +#include + + +string FromTizenString(Tizen::Base::String const & str_tizen) +{ + string utf8Str; + if (str_tizen.GetLength() == 0) + return utf8Str; + Tizen::Base::ByteBuffer * pBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(str_tizen); + if (pBuffer) + { + int byteCount = pBuffer->GetLimit(); + + byteCount--; // Don't copy Zero at the end + if (byteCount > 0) + { + vector chBuf(byteCount); + pBuffer->GetArray((byte *)&chBuf[0], 0, byteCount); + utf8Str.assign(chBuf.begin(), chBuf.end()); + } + delete pBuffer; + } + return utf8Str; +} + +string GetTizenLocale() +{ + Tizen::Base::String languageCode; + Tizen::System::SettingInfo::GetValue(L"http://tizen.org/setting/locale.language", languageCode); + Tizen::Base::String languageCode_truncated; + languageCode.SubString(0, 3, languageCode_truncated); + return CodeFromISO369_2to_1(FromTizenString(languageCode_truncated)); +} + +string CodeFromISO369_2to_1(string const & code_ISO_639_2) +{ + static const string ar [] = + { + "aar", "aa", + "abk", "ab", + "afr", "af", + "aka", "ak", + "sqi", "sq", + "amh", "am", + "ara", "ar", + "arg", "an", + "hye", "hy", + "asm", "as", + "ava", "av", + "ave", "ae", + "aym", "ay", + "aze", "az", + "bak", "ba", + "bam", "bm", + "eus", "eu", + "bel", "be", + "ben", "bn", + "bih", "bh", + "bis", "bi", + "bod", "bo", + "bos", "bs", + "bre", "br", + "bul", "bg", + "mya", "my", + "cat", "ca", + "ces", "cs", + "cha", "ch", + "che", "ce", + "zho", "zh", + "chu", "cu", + "chv", "cv", + "cor", "kw", + "cos", "co", + "cre", "cr", + "cym", "cy", + "ces", "cs", + "dan", "da", + "deu", "de", + "div", "dv", + "nld", "nl", + "dzo", "dz", + "ell", "el", + "eng", "en", + "epo", "eo", + "est", "et", + "eus", "eu", + "ewe", "ee", + "fao", "fo", + "fas", "fa", + "fij", "fj", + "fin", "fi", + "fra", "fr", + "fra", "fr", + "fry", "fy", + "ful", "ff", + "kat", "ka", + "deu", "de", + "gla", "gd", + "gle", "ga", + "glg", "gl", + "glv", "gv", + "ell", "el", + "grn", "gn", + "guj", "gu", + "hat", "ht", + "hau", "ha", + "heb", "he", + "her", "hz", + "hin", "hi", + "hmo", "ho", + "hrv", "hr", + "hun", "hu", + "hye", "hy", + "ibo", "ig", + "ice", "is", + "ido", "io", + "iii", "ii", + "iku", "iu", + "ile", "ie", + "ina", "ia", + "ind", "id", + "ipk", "ik", + "isl", "is", + "ita", "it", + "jav", "jv", + "jpn", "ja", + "kal", "kl", + "kan", "kn", + "kas", "ks", + "kat", "ka", + "kau", "kr", + "kaz", "kk", + "khm", "km", + "kik", "ki", + "kin", "rw", + "kir", "ky", + "kom", "kv", + "kon", "kg", + "kor", "ko", + "kua", "kj", + "kur", "ku", + "lao", "lo", + "lat", "la", + "lav", "lv", + "lim", "li", + "lin", "ln", + "lit", "lt", + "ltz", "lb", + "lub", "lu", + "lug", "lg", + "mkd", "mk", + "mah", "mh", + "mal", "ml", + "mri", "mi", + "mar", "mr", + "msa", "ms", + "mkd", "mk", + "mlg", "mg", + "mlt", "mt", + "mon", "mn", + "mri", "mi", + "msa", "ms", + "mya", "my", + "nau", "na", + "nav", "nv", + "nbl", "nr", + "nde", "nd", + "ndo", "ng", + "nep", "ne", + "nld", "nl", + "nno", "nn", + "nob", "nb", + "nor", "no", + "nya", "ny", + "oci", "oc", + "oji", "oj", + "ori", "or", + "orm", "om", + "oss", "os", + "pan", "pa", + "fas", "fa", + "pli", "pi", + "pol", "pl", + "por", "pt", + "pus", "ps", + "que", "qu", + "roh", "rm", + "ron", "ro", + "ron", "ro", + "run", "rn", + "rus", "ru", + "sag", "sg", + "san", "sa", + "sin", "si", + "slk", "sk", + "slk", "sk", + "slv", "sl", + "sme", "se", + "smo", "sm", + "sna", "sn", + "snd", "sd", + "som", "so", + "sot", "st", + "spa", "es", + "sqi", "sq", + "srd", "sc", + "srp", "sr", + "ssw", "ss", + "sun", "su", + "swa", "sw", + "swe", "sv", + "tah", "ty", + "tam", "ta", + "tat", "tt", + "tel", "te", + "tgk", "tg", + "tgl", "tl", + "tha", "th", + "bod", "bo", + "tir", "ti", + "ton", "to", + "tsn", "tn", + "tso", "ts", + "tuk", "tk", + "tur", "tr", + "twi", "tw", + "uig", "ug", + "ukr", "uk", + "urd", "ur", + "uzb", "uz", + "ven", "ve", + "vie", "vi", + "vol", "vo", + "cym", "cy", + "wln", "wa", + "wol", "wo", + "xho", "xh", + "yid", "yi", + "yor", "yo", + "zha", "za", + "zho", "zh", + "zul", "zu" + }; + for (size_t i = 0; i < sizeof(ar)/sizeof(ar[0]); i += 2) + if (code_ISO_639_2 == ar[i]) + { + return ar[i + 1]; + } + LOG(LDEBUG, ("Language not found", code_ISO_639_2)); + return "en"; +} diff --git a/platform/tizen_string_utils.hpp b/platform/tizen_utils.hpp similarity index 76% rename from platform/tizen_string_utils.hpp rename to platform/tizen_utils.hpp index ae4f7ec03a..41332ff53e 100644 --- a/platform/tizen_string_utils.hpp +++ b/platform/tizen_utils.hpp @@ -13,5 +13,7 @@ namespace Tizen //Convert from Tizen string to std::string string FromTizenString(Tizen::Base::String const & str_tizen); +string CodeFromISO369_2to_1(string const & code_ISO_639_2); +string GetTizenLocale(); #endif diff --git a/tizen/MapsWithMe/src/AboutForm.cpp b/tizen/MapsWithMe/src/AboutForm.cpp index 2b86238734..76f877e924 100644 --- a/tizen/MapsWithMe/src/AboutForm.cpp +++ b/tizen/MapsWithMe/src/AboutForm.cpp @@ -4,7 +4,7 @@ #include "AppResourceId.h" #include "../../../base/logging.hpp" #include "../../../platform/settings.hpp" -#include "../../../platform/tizen_string_utils.hpp" +#include "../../../platform/tizen_utils.hpp" #include #include #include diff --git a/tizen/MapsWithMe/src/FormFactory.cpp b/tizen/MapsWithMe/src/FormFactory.cpp index bf4760515f..09a357f09b 100644 --- a/tizen/MapsWithMe/src/FormFactory.cpp +++ b/tizen/MapsWithMe/src/FormFactory.cpp @@ -3,7 +3,7 @@ #include "SettingsForm.hpp" #include "AboutForm.hpp" #include "../../../base/logging.hpp" -#include "../../../platform/tizen_string_utils.hpp" +#include "../../../platform/tizen_utils.hpp" using namespace Tizen::Ui::Scenes; using namespace Tizen::Base; diff --git a/tizen/MapsWithMe/src/MapsWithMeForm.cpp b/tizen/MapsWithMe/src/MapsWithMeForm.cpp index 22674c29ce..7d7ea12be7 100644 --- a/tizen/MapsWithMe/src/MapsWithMeForm.cpp +++ b/tizen/MapsWithMe/src/MapsWithMeForm.cpp @@ -4,7 +4,7 @@ #include "SceneRegister.hpp" #include "../../../map/framework.hpp" #include "../../../gui/controller.hpp" -#include "../../../platform/tizen_string_utils.hpp" +#include "../../../platform/tizen_utils.hpp" #include "../../../platform/settings.hpp" #include #include