Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Unified Diff: chrome/common/extensions/extension_message_bundle.cc

Issue 293037: Implementing better fallback algorithm.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/extension_message_bundle.cc
===================================================================
--- chrome/common/extensions/extension_message_bundle.cc (revision 29587)
+++ chrome/common/extensions/extension_message_bundle.cc (working copy)
@@ -5,8 +5,10 @@
#include "chrome/common/extensions/extension_message_bundle.h"
#include <string>
+#include <vector>
#include "base/hash_tables.h"
+#include "base/linked_ptr.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/values.h"
@@ -34,54 +36,36 @@
// static
ExtensionMessageBundle* ExtensionMessageBundle::Create(
- const DictionaryValue& default_locale_catalog,
- const DictionaryValue& current_locale_catalog,
+ const CatalogVector& locale_catalogs,
std::string* error) {
scoped_ptr<ExtensionMessageBundle> message_bundle(
new ExtensionMessageBundle);
- if (!message_bundle->Init(default_locale_catalog,
- current_locale_catalog,
- error))
+ if (!message_bundle->Init(locale_catalogs, error))
return NULL;
return message_bundle.release();
}
-bool ExtensionMessageBundle::Init(const DictionaryValue& default_locale_catalog,
- const DictionaryValue& current_locale_catalog,
+bool ExtensionMessageBundle::Init(const CatalogVector& locale_catalogs,
std::string* error) {
dictionary_.clear();
- // Create a single dictionary out of default and current_locale catalogs.
- // If message is missing from current_locale catalog, we take one from default
- // catalog.
- DictionaryValue::key_iterator key_it = current_locale_catalog.begin_keys();
- for (; key_it != current_locale_catalog.end_keys(); ++key_it) {
- std::string key(StringToLowerASCII(WideToUTF8(*key_it)));
- if (!IsValidName(*key_it))
- return BadKeyMessage(key, error);
- std::string value;
- if (!GetMessageValue(*key_it, current_locale_catalog, &value, error))
- return false;
- // Keys are not case-sensitive.
- dictionary_[key] = value;
+ CatalogVector::const_reverse_iterator it = locale_catalogs.rbegin();
+ for (; it != locale_catalogs.rend(); ++it) {
+ DictionaryValue* catalog = (*it).get();
+ DictionaryValue::key_iterator key_it = catalog->begin_keys();
+ for (; key_it != catalog->end_keys(); ++key_it) {
+ std::string key(StringToLowerASCII(WideToUTF8(*key_it)));
+ if (!IsValidName(*key_it))
+ return BadKeyMessage(key, error);
+ std::string value;
+ if (!GetMessageValue(*key_it, *catalog, &value, error))
+ return false;
+ // Keys are not case-sensitive.
+ dictionary_[key] = value;
+ }
}
- key_it = default_locale_catalog.begin_keys();
- for (; key_it != default_locale_catalog.end_keys(); ++key_it) {
- std::string key(StringToLowerASCII(WideToUTF8(*key_it)));
- if (!IsValidName(*key_it))
- return BadKeyMessage(key, error);
- // Add only messages that are not provided by app_catalog.
- if (dictionary_.find(key) != dictionary_.end())
- continue;
- std::string value;
- if (!GetMessageValue(*key_it, default_locale_catalog, &value, error))
- return false;
- // Keys are not case-sensitive.
- dictionary_[key] = value;
- }
-
return true;
}
« no previous file with comments | « chrome/common/extensions/extension_message_bundle.h ('k') | chrome/common/extensions/extension_message_bundle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698