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

Unified Diff: chrome/renderer/translate_helper.cc

Issue 12221085: Translate: split language code typo correction to apply unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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 | « chrome/renderer/translate_helper.h ('k') | chrome/renderer/translate_helper_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/translate_helper.cc
diff --git a/chrome/renderer/translate_helper.cc b/chrome/renderer/translate_helper.cc
index 54797107f4ed0e5ff160526c936e010937a72518..be9d7fe1ab40fa09b3b38832ba7860020701869e 100644
--- a/chrome/renderer/translate_helper.cc
+++ b/chrome/renderer/translate_helper.cc
@@ -93,26 +93,7 @@ void TranslateHelper::PageCaptured(const string16& contents) {
// relevant for things like langauge textbooks). This distinction
// shouldn't affect translation.
std::string language = document.contentLanguage().utf8();
- size_t coma_index = language.find(',');
- if (coma_index != std::string::npos) {
- // There are more than 1 language specified, just keep the first one.
- language = language.substr(0, coma_index);
- }
- TrimWhitespaceASCII(language, TRIM_ALL, &language);
-
- // An underscore instead of a dash is a frequent mistake.
- size_t underscore_index = language.find('_');
- if (underscore_index != std::string::npos)
- language[underscore_index] = '-';
-
- // Change everything up to a dash to lower-case and everything after to upper.
- size_t dash_index = language.find('-');
- if (dash_index != std::string::npos) {
- language = StringToLowerASCII(language.substr(0, dash_index)) +
- StringToUpperASCII(language.substr(dash_index));
- } else {
- language = StringToLowerASCII(language);
- }
+ CorrectLanguageCodeTypo(&language);
#if defined(ENABLE_LANGUAGE_DETECTION)
if (language.empty()) {
@@ -242,7 +223,35 @@ bool TranslateHelper::DontDelayTasks() {
// TranslateHelper, private:
//
// static
+void TranslateHelper::CorrectLanguageCodeTypo(std::string* code) {
+ DCHECK(code);
+
+ size_t coma_index = code->find(',');
+ if (coma_index != std::string::npos) {
+ // There are more than 1 language specified, just keep the first one.
+ *code = code->substr(0, coma_index);
+ }
+ TrimWhitespaceASCII(*code, TRIM_ALL, code);
+
+ // An underscore instead of a dash is a frequent mistake.
+ size_t underscore_index = code->find('_');
+ if (underscore_index != std::string::npos)
+ (*code)[underscore_index] = '-';
+
+ // Change everything up to a dash to lower-case and everything after to upper.
+ size_t dash_index = code->find('-');
+ if (dash_index != std::string::npos) {
+ *code = StringToLowerASCII(code->substr(0, dash_index)) +
+ StringToUpperASCII(code->substr(dash_index));
+ } else {
+ *code = StringToLowerASCII(*code);
+ }
+}
+
+// static
void TranslateHelper::ConvertLanguageCodeSynonym(std::string* code) {
+ DCHECK(code);
+
// Apply liner search here because number of items in the list is just four.
for (size_t i = 0; i < arraysize(kLanguageCodeSynonyms); ++i) {
if (code->compare(kLanguageCodeSynonyms[i].from) == 0) {
« no previous file with comments | « chrome/renderer/translate_helper.h ('k') | chrome/renderer/translate_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698