+void Manifest::SetSystemLocale(const std::string& locale) {
+ scoped_ptr<List> list_for_expand(new List);
+ list_for_expand->push_back(locale);
+ list_for_expand->push_back(default_locale_);
+ list_for_expand->push_back(kLocaleUnlocalized);
+ list_for_expand->push_back(kLocaleAuto);
+ list_for_expand->push_back(kLocaleFirstOne);
+ user_agent_locales_ = ExpandUserAgentLocalesList(list_for_expand);
+}
+
+void Manifest::ParseWGTI18n() {
+ data_->GetString(application_widget_keys::kDefaultLocaleKey,
+ &default_locale_);
+ default_locale_ = StringToLowerASCII(default_locale_);
+
+ ParseWGTI18nEachPath(kWidgetNamePath);
+ ParseWGTI18nEachPath(kWidgetDecriptionPath);
+ ParseWGTI18nEachPath(kWidgetLicensePath);
+}
+
+// We might get one element of a list of element from path,
+// and we parse each element for fast access.
+// For example config.xml is:
+// <widget>
+// <name>unlocalized name</name>
+// <name xml:lang="zh-CN">zh-CN name</name>
+// <name xml:lang="en-US" short="en-US short">en-US name</name>
+// </widget>
+// The path for value in i18n_data_ are :
+// "widget.name.#text.@unlocalized" => "unlocalized name".
+// "widget.name.#text.zh-cn" => "zh-CN name".
+// "widget.name.#text.en-us" => "en-US name".
+// "widget.name.@short.en-us" => "en-US short".
+// "widget.name.#text.*" => "unlocalized name". (the first one)
+// "widget.name.@short.*" => "". (the first one do not have a short name)
+void Manifest::ParseWGTI18nEachPath(const std::string& path) {
+ base::Value* value = NULL;
+ if (!data_->Get(path, &value))
+ return;
+
+ if (value->IsType(base::Value::TYPE_DICTIONARY)) {
+ ParseWGTI18nEachElement(value, path);
+ ParseWGTI18nEachElement(value, path, kLocaleFirstOne);
+ } else if (value->IsType(base::Value::TYPE_LIST)) {
+ base::ListValue* list;
+ value->GetAsList(&list);
+
+ bool get_first_one = false;
+ for (base::ListValue::iterator it = list->begin();
+ it != list->end(); ++it) {
+ ParseWGTI18nEachElement(*it, path);
+ if (!get_first_one)
+ get_first_one = ParseWGTI18nEachElement(*it, path, kLocaleFirstOne);
+ }
+ }
+ // After Parse we remove this path from data_ for saving memory.
+ scoped_ptr<base::Value> remove_value;
+ data_->Remove(path, &remove_value);
+}
+
+bool Manifest::ParseWGTI18nEachElement(base::Value* value,
+ const std::string& path,
+ const std::string& locale) {
+ base::DictionaryValue* dict;
+ if (!value->GetAsDictionary(&dict))
+ return false;
+
+ std::string xml_lang(locale);
+ if (locale.empty())
+ dict->GetString(application_widget_keys::kXmlLangKey, &xml_lang);
+
+ base::DictionaryValue::Iterator iter(*dict);
+ while (!iter.IsAtEnd()) {
+ std::string locale_key(
+ GetLocalizedKey(path + kPathConnectSymbol + iter.key(), xml_lang));
+ if (!i18n_data_->Get(locale_key, NULL))
+ i18n_data_->Set(locale_key, iter.value().DeepCopy());
+
+ iter.Advance();
+ }
+
+ return true;
+}
+