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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/renderer/translate_helper_browsertest.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 e2d23bf25baec9cc2e0073ddbbb04ff4a782ede6..382b60ce3eba7fe383f389d1a0d7f400c18c4237 100644
--- a/chrome/renderer/translate_helper.cc
+++ b/chrome/renderer/translate_helper.cc
@@ -78,7 +78,21 @@ void TranslateHelper::PageCaptured(const string16& contents) {
language = language.substr(0, coma_index);
}
TrimWhitespaceASCII(language, TRIM_ALL, &language);
- language = StringToLowerASCII(language);
+
+ // Underscores instead of dashes are a frequent mistake.
+ size_t underscore_index = language.find('_');
+ if (underscore_index != std::string::npos) {
+ language[underscore_index] = '-';
MAD 2012/11/06 18:00:20 No need for {} here...
bcwhite 2012/11/06 18:37:49 Doh! I am going to do that _every_ time! Fixed.
+ }
MAD 2012/11/06 18:00:20 Add a DCHECK that there are not other '_' in the s
bcwhite 2012/11/06 18:37:49 We're parsing user-supplied input here. Is crashi
MAD 2012/11/06 18:39:30 OK, fine...
+
+ // 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)) +
MAD 2012/11/06 18:00:20 Add a DCHECK that there are no other '-' in the st
bcwhite 2012/11/06 18:37:49 Same as above. I don't think it's a problem as ma
+ StringToUpperASCII(language.substr(dash_index));
+ } else {
+ language = StringToLowerASCII(language);
+ }
if (language.empty()) {
base::TimeTicks begin_time = base::TimeTicks::Now();
« 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