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

Side by Side Diff: chrome/renderer/translate_helper.cc

Issue 11358121: support common content-language mistakes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: improved test name Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/translate_helper_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/translate_helper.h" 5 #include "chrome/renderer/translate_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // language of the intended audience (a distinction really only 71 // language of the intended audience (a distinction really only
72 // relevant for things like langauge textbooks). This distinction 72 // relevant for things like langauge textbooks). This distinction
73 // shouldn't affect translation. 73 // shouldn't affect translation.
74 std::string language = document.contentLanguage().utf8(); 74 std::string language = document.contentLanguage().utf8();
75 size_t coma_index = language.find(','); 75 size_t coma_index = language.find(',');
76 if (coma_index != std::string::npos) { 76 if (coma_index != std::string::npos) {
77 // There are more than 1 language specified, just keep the first one. 77 // There are more than 1 language specified, just keep the first one.
78 language = language.substr(0, coma_index); 78 language = language.substr(0, coma_index);
79 } 79 }
80 TrimWhitespaceASCII(language, TRIM_ALL, &language); 80 TrimWhitespaceASCII(language, TRIM_ALL, &language);
81 language = StringToLowerASCII(language); 81
82 // An underscore instead of a dash is a frequent mistake.
83 size_t underscore_index = language.find('_');
84 if (underscore_index != std::string::npos)
85 language[underscore_index] = '-';
86
87 // Change everything up to a dash to lower-case and everything after to upper.
88 size_t dash_index = language.find('-');
89 if (dash_index != std::string::npos) {
90 language = StringToLowerASCII(language.substr(0, dash_index)) +
91 StringToUpperASCII(language.substr(dash_index));
92 } else {
93 language = StringToLowerASCII(language);
94 }
82 95
83 if (language.empty()) { 96 if (language.empty()) {
84 base::TimeTicks begin_time = base::TimeTicks::Now(); 97 base::TimeTicks begin_time = base::TimeTicks::Now();
85 language = DetermineTextLanguage(contents); 98 language = DetermineTextLanguage(contents);
86 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", 99 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
87 base::TimeTicks::Now() - begin_time); 100 base::TimeTicks::Now() - begin_time);
88 } else { 101 } else {
89 VLOG(9) << "PageLanguageFromMetaTag: " << language; 102 VLOG(9) << "PageLanguageFromMetaTag: " << language;
90 } 103 }
91 104
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 WebView* web_view = render_view()->GetWebView(); 439 WebView* web_view = render_view()->GetWebView();
427 if (!web_view) { 440 if (!web_view) {
428 // When the WebView is going away, the render view should have called 441 // When the WebView is going away, the render view should have called
429 // CancelPendingTranslation() which should have stopped any pending work, so 442 // CancelPendingTranslation() which should have stopped any pending work, so
430 // that case should not happen. 443 // that case should not happen.
431 NOTREACHED(); 444 NOTREACHED();
432 return NULL; 445 return NULL;
433 } 446 }
434 return web_view->mainFrame(); 447 return web_view->mainFrame();
435 } 448 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/translate_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698