OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/translate/language_detection/language_detection_util.h" | 5 #include "components/translate/language_detection/language_detection_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, | 103 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, |
104 &num_languages, NULL, &text_bytes); | 104 &num_languages, NULL, &text_bytes); |
105 is_valid_language = cld_language != NUM_LANGUAGES && | 105 is_valid_language = cld_language != NUM_LANGUAGES && |
106 cld_language != UNKNOWN_LANGUAGE && | 106 cld_language != UNKNOWN_LANGUAGE && |
107 cld_language != TG_UNKNOWN_LANGUAGE; | 107 cld_language != TG_UNKNOWN_LANGUAGE; |
108 break; | 108 break; |
109 } | 109 } |
110 #endif | 110 #endif |
111 #if !defined(CLD_VERSION) || CLD_VERSION==2 | 111 #if !defined(CLD_VERSION) || CLD_VERSION==2 |
112 case 2: { | 112 case 2: { |
113 std::string utf8_text(UTF16ToUTF8(text)); | 113 std::string utf8_text(base::UTF16ToUTF8(text)); |
114 CLD2::Language language3[3]; | 114 CLD2::Language language3[3]; |
115 int percent3[3]; | 115 int percent3[3]; |
116 CLD2::DetectLanguageSummary( | 116 CLD2::DetectLanguageSummary( |
117 utf8_text.c_str(), (int)utf8_text.size(), true, language3, percent3, | 117 utf8_text.c_str(), (int)utf8_text.size(), true, language3, percent3, |
118 &text_bytes, &is_reliable); | 118 &text_bytes, &is_reliable); |
119 cld_language = language3[0]; | 119 cld_language = language3[0]; |
120 is_valid_language = cld_language != CLD2::NUM_LANGUAGES && | 120 is_valid_language = cld_language != CLD2::NUM_LANGUAGES && |
121 cld_language != CLD2::UNKNOWN_LANGUAGE && | 121 cld_language != CLD2::UNKNOWN_LANGUAGE && |
122 cld_language != CLD2::TG_UNKNOWN_LANGUAGE; | 122 cld_language != CLD2::TG_UNKNOWN_LANGUAGE; |
123 break; | 123 break; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // distinguish from English, and the language is one of well-known languages | 377 // distinguish from English, and the language is one of well-known languages |
378 // which often provide "en-*" meta information mistakenly. | 378 // which often provide "en-*" meta information mistakenly. |
379 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { | 379 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { |
380 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) | 380 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) |
381 return true; | 381 return true; |
382 } | 382 } |
383 return false; | 383 return false; |
384 } | 384 } |
385 | 385 |
386 } // namespace translate | 386 } // namespace translate |
OLD | NEW |