Pkgmgr's wgt backendlib - fixing name locale for package
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 12 Aug 2013 11:20:39 +0000 (13:20 +0200)
committerSoo-Hyun Choi <sh9.choi@samsung.com>
Wed, 14 Aug 2013 03:04:40 +0000 (12:04 +0900)
[Issue#]       LINUXWRT-792 / WGL-406
[Bug]          Locale isn't correctly dipatched
[Cause]        Lookup should be done without subtags too
               (that wasn't fixed when writing LocalisationTagsSingleton).
[Solution]     Use code from localisation module
[Verification] Try to install widget ta-de-004.wgt (located in wrt-extra)
               from myfiles app (copy file to /opt/usr/media/Others/).
               Displayed widget name in popup should be "PASS".

Change-Id: I4468619e441f32f1d744bba4eba08a8579fbe403

src/pkg-manager/backendlib.cpp

index ceca1ba..7995119 100644 (file)
@@ -28,7 +28,6 @@
 #include <dlog.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <vcore/VCore.h>
-#include <vconf.h>
 #include <dpl/wrt-dao-ro/WrtDatabase.h>
 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
@@ -46,6 +45,7 @@
 #include <dpl/binary_queue.h>
 #include <dpl/file_input.h>
 #include <dpl/wrt-dao-ro/config_parser_data.h>
+#include <dpl/localization/LanguageTagsProvider.h>
 #include "root_parser.h"
 #include "widget_parser.h"
 #include "parser_runner.h"
@@ -388,43 +388,44 @@ int getWidgetDetailInfoFromPackage(const char* pkgPath,
     DPL::Optional<DPL::String> name;
     DPL::Optional<DPL::String> desc;
 
-    DPL::OptionalString defaultLocale = configInfo.defaultlocale;
+    LanguageTags tags = LanguageTagsProviderSingleton::Instance().getLanguageTags();
 
-    char* language = vconf_get_str(VCONFKEY_LANGSET);
+    auto toLowerCase = [](const DPL::String & r)
+    {
+        DPL::String result;
+        std::transform(r.begin(), r.end(), std::inserter(result, result.begin()), ::tolower);
+        return result;
+    };
 
-    DPL::String inLocaleString = DPL::FromUTF8String(language);
-    DPL::String locString = inLocaleString.substr(
-            0, inLocaleString.find_first_of(L"."));
-    std::replace(locString.begin(), locString.end(), '_', '-');
+    if (!!configInfo.defaultlocale)
+    {
+        Locale & dl = *configInfo.defaultlocale;
+        configInfo.defaultlocale = toLowerCase(dl);
+    }
 
-    FOREACH(localizedData, configInfo.localizedDataSet)
+    bool found = false;
+    FOREACH(tag, tags)
     {
-        Locale i = localizedData->first;
-        std::transform( locString.begin(),
-                locString.end(),
-                locString.begin(),
-                ::tolower );
-        std::transform( i.begin(), i.end(), i.begin(), ::tolower );
-        std::size_t found = locString.find(i);
-        std::size_t found2 = i.find(locString);
-
-        if (!!defaultLocale) {
-            if (defaultLocale == i) {
+        *tag = toLowerCase(*tag);
+        FOREACH(localizedData, configInfo.localizedDataSet)
+        {
+            Locale i = localizedData->first;
+            i = toLowerCase(i);
+
+            if (!!configInfo.defaultlocale && *configInfo.defaultlocale == i)
+            {
                 name = localizedData->second.name;
                 desc = localizedData->second.description;
+            }
+            if (*tag == i)
+            {
+                name = localizedData->second.name;
+                desc = localizedData->second.description;
+                found = true;
                 break;
             }
-        } else if (found != std::string::npos
-                || found2 != std::string::npos) {
-            name = localizedData->second.name;
-            desc = localizedData->second.description;
-            break;
-        }
-        else {
-            name = localizedData->second.name;
-            desc = localizedData->second.description;
-            continue;
         }
+        if(found) break;
     }
 
     if( !name.IsNull()) {