Index: chrome/browser/intents/cws_intents_registry.cc |
diff --git a/chrome/browser/intents/cws_intents_registry.cc b/chrome/browser/intents/cws_intents_registry.cc |
index 78fc48b2fe855bba84c87084bd334e603374cf4f..96fd943aa1d8c9a30c4234283ffee7c4b484aa0e 100644 |
--- a/chrome/browser/intents/cws_intents_registry.cc |
+++ b/chrome/browser/intents/cws_intents_registry.cc |
@@ -10,6 +10,8 @@ |
#include "base/stl_util.h" |
#include "base/string16.h" |
#include "base/utf_string_conversions.h" |
+#include "chrome/common/extensions/extension_l10n_util.h" |
+#include "chrome/common/extensions/message_bundle.h" |
#include "chrome/browser/intents/api_key.h" |
#include "chrome/browser/net/chrome_url_request_context.h" |
#include "chrome/browser/webdata/web_data_service.h" |
@@ -38,6 +40,17 @@ const char kMaxSuggestions[] = "15"; |
const char kCWSIntentServiceURL[] = |
"https://www.googleapis.com/chromewebstore/v1.1b/items/intent"; |
+// Determines if a string is a candidate for localization. |
+bool ShouldLocalize(const std::string& value) { |
+ std::string::size_type index = 0; |
+ index = value.find(extensions::MessageBundle::kMessageBegin); |
+ if (index == std::string::npos) |
+ return false; |
+ |
+ index = value.find(extensions::MessageBundle::kMessageEnd, index); |
+ return (index != std::string::npos); |
+} |
+ |
// Parses a JSON |response| from the CWS into a list of suggested extensions, |
// stored in |intents|. |intents| must not be NULL. |
void ParseResponse(const std::string& response, |
@@ -92,6 +105,38 @@ void ParseResponse(const std::string& response, |
continue; |
info.icon_url = GURL(url_string); |
+ // Need to parse CWS reply, since it is not pre-l10n'd. |
+ ListValue* all_locales = NULL; |
+ if (ShouldLocalize(UTF16ToUTF8(info.name)) && |
+ item->GetList("locale_data", &all_locales)) { |
+ std::map<std::string, std::string> localized_title; |
+ |
+ for (ListValue::const_iterator locale_iter(all_locales->begin()); |
+ locale_iter != all_locales->end(); ++locale_iter) { |
+ DictionaryValue* locale = static_cast<DictionaryValue*>(*locale_iter); |
+ |
+ std::string locale_id, title; |
+ if (!locale->GetString("locale_string", &locale_id) || |
+ !locale->GetString("title", &title)) |
+ continue; |
+ |
+ localized_title[locale_id] = title; |
+ } |
+ |
+ std::vector<std::string> valid_locales; |
+ extension_l10n_util::GetAllFallbackLocales( |
+ extension_l10n_util::CurrentLocaleOrDefault(), |
+ "all", |
+ &valid_locales); |
+ for (std::vector<std::string>::iterator iter = valid_locales.begin(); |
+ iter != valid_locales.end(); ++iter) { |
+ if (localized_title.count(*iter)) { |
+ info.name = UTF8ToUTF16(localized_title[*iter]); |
+ break; |
+ } |
+ } |
+ } |
+ |
intents->push_back(info); |
} |
} |