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

Unified Diff: chrome/browser/intents/cws_intents_registry.cc

Issue 10790087: [Web Intents] Localization of intent titles for CWS suggestions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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/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..cd8aee2844aef0aca53d99e0beef1ca95abf049b 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/extension_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(ExtensionMessageBundle::kMessageBegin);
+ if (index == std::string::npos)
+ return false;
+
+ index = value.find(ExtensionMessageBundle::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,37 @@ void ParseResponse(const std::string& response,
continue;
info.icon_url = GURL(url_string);
Greg Billock 2012/07/20 15:58:30 Can you add a comment about why we need this block
groby-ooo-7-16 2012/07/20 22:59:54 Done.
+ 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))
Greg Billock 2012/07/20 15:58:30 So this isn't the normal place, so the extension l
groby-ooo-7-16 2012/07/20 22:59:54 That is correct. There's also the point that the C
+ continue;
+
+ localized_title[locale_id] = title;
+ }
+
+ std::vector<std::string> valid_locales;
Greg Billock 2012/07/20 15:58:30 Can you just use vector<string> here and below? Th
groby-ooo-7-16 2012/07/20 22:59:54 As far as I can tell, we always prefix. On 2012/0
+ extension_l10n_util::GetAllFallbackLocales(
+ extension_l10n_util::CurrentLocaleOrDefault(),
Greg Billock 2012/07/20 15:58:30 Shouldn't the util class compose these default/cur
groby-ooo-7-16 2012/07/20 22:59:54 No, because the util class is shared with extensio
+ "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);
}
}

Powered by Google App Engine
This is Rietveld 408576698