Change runtim-info keys to system-settings keys to apply vconf-internal-keys changes
[platform/framework/web/nwrt.git] / src / common / locale_manager.cc
index 83e2d22..d31956c 100755 (executable)
@@ -1,10 +1,22 @@
-// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
 
 #include "common/locale_manager.h"
 
-#include <runtime_info.h>
+#include <system_settings.h>
 #include <memory>
 #include <algorithm>
 
@@ -34,18 +46,18 @@ LocaleManager::LocaleManager() {
 }
 
 LocaleManager::~LocaleManager() {
-  runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE);
+  system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE);
 }
 
 void LocaleManager::EnableAutoUpdate(bool enable) {
   if (enable) {
-    auto callback = [](runtime_info_key_e, void* user_data) {
+    auto callback = [](system_settings_key_e, void* user_data) {
         LocaleManager* locale = static_cast<LocaleManager*>(user_data);
         locale->UpdateSystemLocale();
     };
-    runtime_info_set_changed_cb(RUNTIME_INFO_KEY_LANGUAGE, callback, this);
+    system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, callback, this);
   } else {
-    runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_LANGUAGE);
+    system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE);
   }
 }
 
@@ -62,8 +74,8 @@ void LocaleManager::SetDefaultLocale(const std::string& locale) {
 
 void LocaleManager::UpdateSystemLocale() {
   char* str = NULL;
-  if (RUNTIME_INFO_ERROR_NONE !=
-      runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &str)
+  if (SYSTEM_SETTINGS_ERROR_NONE !=
+      system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &str)
      || str == NULL) {
     return;
   }
@@ -97,4 +109,27 @@ void LocaleManager::UpdateSystemLocale() {
   }
 }
 
+std::string LocaleManager::GetLocalizedString(const StringMap& strmap) {
+  if (strmap.empty()) {
+    return std::string();
+  }
+
+  // find string with system locales
+  for (auto& locale : system_locales_) {
+    auto it = strmap.find(locale);
+    if (it != strmap.end()) {
+      return it->second;
+    }
+  }
+
+  // find string with empty locale
+  auto it = strmap.find("");
+  if (it != strmap.end()) {
+    return it->second;
+  }
+
+  // If localized string is not found, return first string.
+  return strmap.begin()->second;
+}
+
 }  // namespace wrt