Default widget locale adding to language tags
authorMarcin Kaminski <marcin.ka@samsung.com>
Mon, 5 Nov 2012 16:03:30 +0000 (17:03 +0100)
committerJihoon Chung <jihoon.chung@samsung.com>
Mon, 12 Nov 2012 08:18:43 +0000 (17:18 +0900)
[Issue#] N/A
[Feature] New LanguageTagsProvider API: method that
allows to add widget default locale to current
language tags list
[Cause] Localization related refactoring in WRT
[Solution] N/A

[Verification] Build package. Additional
unit tests will be provided.

Change-Id: Ic3a17a79ba493d1e3e523b352bc1a1f6d67c0889

modules/localization/include/LanguageTagsProvider.h
modules/localization/src/LanguageTagsProvider.cpp

index c32d0fe..bb3e48c 100644 (file)
@@ -54,6 +54,16 @@ public:
     void resetLanguageTags();
 
     /*
+     * Adds default widget locales to language tags if
+     * it doesn't exist within actual tags.
+     * Default locales i added:
+     * - at the beginning if less then 2 tags exists on list
+     * - just before empty ("") locales - pre-last position
+     * - at the end if last position is not empty locale
+     */
+    void addWidgetDefaultLocales(const DPL::String&);
+
+    /*
      * Function converts language tag string (i.e. en-US)
      * into locales string (en_US).
      */
index 120490a..b75de8b 100644 (file)
@@ -65,6 +65,24 @@ void LanguageTagsProvider::resetLanguageTags()
     this->loadSystemTags();
 }
 
+void LanguageTagsProvider::addWidgetDefaultLocales(const DPL::String& defaultLocale){
+    if (defaultLocale.size() > 0 &&
+        std::find(m_languageTagsList.begin(), m_languageTagsList.end(), defaultLocale) == m_languageTagsList.end())
+    {
+        if (m_languageTagsList.size() < 2) {
+            m_languageTagsList.push_front(defaultLocale);
+        } else {
+            LanguageTags::iterator placeToInsert = m_languageTagsList.end();
+            --placeToInsert;
+            if (*placeToInsert != L"")
+            {
+                ++placeToInsert;
+            }
+            m_languageTagsList.insert(placeToInsert, defaultLocale);
+        }
+    }
+}
+
 DPL::String LanguageTagsProvider::BCP47LanguageTagToLocale(const DPL::String& inLanguageTag)
 {
     DPL::String languageTag(inLanguageTag);