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

Unified Diff: chrome/browser/translate/translate_prefs.cc

Issue 23522021: Translate: Bug fix: Remove the language sub code when merging to the blocked language list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 7 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/translate/translate_prefs_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/translate/translate_prefs.cc
diff --git a/chrome/browser/translate/translate_prefs.cc b/chrome/browser/translate/translate_prefs.cc
index 6d5fabf2cb90e96babd6b96e1311af64a10017ae..a6b51d930d01e30040955c2c152cc81f094a62f4 100644
--- a/chrome/browser/translate/translate_prefs.cc
+++ b/chrome/browser/translate/translate_prefs.cc
@@ -44,6 +44,26 @@ void GetBlacklistedLanguages(const PrefService* prefs,
}
}
+// Converts the language code for Translate. This removes the sub code (like
+// -US) except for Chinese, and converts the synonyms.
+// The same logic exists at language_options.js, and please keep consistensy
+// with the JavaScript file.
+std::string ConvertLangCodeForTranslation(const std::string &lang) {
+ std::vector<std::string> tokens;
+ base::SplitString(lang, '-', &tokens);
+ if (tokens.size() < 1)
+ return lang;
+
+ std::string main_part = tokens[0];
+
+ // Translate doesn't support General Chinese and the sub code is necessary.
+ if (main_part == "zh")
+ return lang;
+
+ TranslateUtil::ToTranslateLanguageSynonym(&main_part);
+ return main_part;
+}
+
} // namespace
namespace {
@@ -390,15 +410,14 @@ void TranslatePrefs::CreateBlockedLanguages(
for (std::vector<std::string>::const_iterator it = accept_languages.begin();
it != accept_languages.end(); ++it) {
- std::string lang = *it;
- TranslateUtil::ToTranslateLanguageSynonym(&lang);
+ std::string converted_lang = ConvertLangCodeForTranslation(*it);
// Regarding http://crbug.com/36182, even though English exists in Accept
// language list, English could be translated on non-English locale.
- if (lang == "en" && !is_ui_english)
+ if (converted_lang == "en" && !is_ui_english)
continue;
- result.insert(lang);
+ result.insert(converted_lang);
}
blocked_languages->insert(blocked_languages->begin(),
« no previous file with comments | « no previous file | chrome/browser/translate/translate_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698