From 2ac5913f6f1312ce865469d65e6ef1be4f7b634f Mon Sep 17 00:00:00 2001 From: Marcin Kaminski Date: Mon, 5 Nov 2012 17:03:30 +0100 Subject: [PATCH] Default widget locale adding to language tags [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 | 10 ++++++++++ modules/localization/src/LanguageTagsProvider.cpp | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/modules/localization/include/LanguageTagsProvider.h b/modules/localization/include/LanguageTagsProvider.h index c32d0fe..bb3e48c 100644 --- a/modules/localization/include/LanguageTagsProvider.h +++ b/modules/localization/include/LanguageTagsProvider.h @@ -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). */ diff --git a/modules/localization/src/LanguageTagsProvider.cpp b/modules/localization/src/LanguageTagsProvider.cpp index 120490a..b75de8b 100644 --- a/modules/localization/src/LanguageTagsProvider.cpp +++ b/modules/localization/src/LanguageTagsProvider.cpp @@ -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); -- 2.7.4