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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 if (language.empty()) { | 238 if (language.empty()) { |
239 translate::ReportLanguageVerification( | 239 translate::ReportLanguageVerification( |
240 translate::LANGUAGE_VERIFICATION_CLD_ONLY); | 240 translate::LANGUAGE_VERIFICATION_CLD_ONLY); |
241 return cld_language; | 241 return cld_language; |
242 } | 242 } |
243 | 243 |
244 if (cld_language == kUnknownLanguageCode) { | 244 if (cld_language == kUnknownLanguageCode) { |
245 translate::ReportLanguageVerification( | 245 translate::ReportLanguageVerification( |
246 translate::LANGUAGE_VERIFICATION_UNKNOWN); | 246 translate::LANGUAGE_VERIFICATION_UNKNOWN); |
247 return language; | 247 return language; |
248 } else if (CanCLDComplementSubCode(language, cld_language)) { | 248 } |
| 249 |
| 250 if (CanCLDComplementSubCode(language, cld_language)) { |
249 translate::ReportLanguageVerification( | 251 translate::ReportLanguageVerification( |
250 translate::LANGUAGE_VERIFICATION_CLD_COMPLEMENT_SUB_CODE); | 252 translate::LANGUAGE_VERIFICATION_CLD_COMPLEMENT_SUB_CODE); |
251 return cld_language; | 253 return cld_language; |
252 } else if (IsSameOrSimilarLanguages(language, cld_language)) { | 254 } |
| 255 |
| 256 if (IsSameOrSimilarLanguages(language, cld_language)) { |
253 translate::ReportLanguageVerification( | 257 translate::ReportLanguageVerification( |
254 translate::LANGUAGE_VERIFICATION_CLD_AGREE); | 258 translate::LANGUAGE_VERIFICATION_CLD_AGREE); |
255 return language; | 259 return language; |
256 } else if (MaybeServerWrongConfiguration(language, cld_language)) { | 260 } |
| 261 |
| 262 if (MaybeServerWrongConfiguration(language, cld_language)) { |
257 translate::ReportLanguageVerification( | 263 translate::ReportLanguageVerification( |
258 translate::LANGUAGE_VERIFICATION_TRUST_CLD); | 264 translate::LANGUAGE_VERIFICATION_TRUST_CLD); |
259 return cld_language; | 265 return cld_language; |
260 } else { | |
261 translate::ReportLanguageVerification( | |
262 translate::LANGUAGE_VERIFICATION_CLD_DISAGREE); | |
263 // Content-Language value might be wrong because CLD says that this page | |
264 // is written in another language with confidence. | |
265 // In this case, Chrome doesn't rely on any of the language codes, and | |
266 // gives up suggesting a translation. | |
267 return std::string(kUnknownLanguageCode); | |
268 } | 266 } |
269 | 267 |
270 return language; | 268 // Content-Language value might be wrong because CLD says that this page is |
| 269 // written in another language with confidence. In this case, Chrome doesn't |
| 270 // rely on any of the language codes, and gives up suggesting a translation. |
| 271 translate::ReportLanguageVerification( |
| 272 translate::LANGUAGE_VERIFICATION_CLD_DISAGREE); |
| 273 return kUnknownLanguageCode; |
271 } | 274 } |
272 | 275 |
273 void CorrectLanguageCodeTypo(std::string* code) { | 276 void CorrectLanguageCodeTypo(std::string* code) { |
274 DCHECK(code); | 277 DCHECK(code); |
275 | 278 |
276 size_t coma_index = code->find(','); | 279 size_t coma_index = code->find(','); |
277 if (coma_index != std::string::npos) { | 280 if (coma_index != std::string::npos) { |
278 // There are more than 1 language specified, just keep the first one. | 281 // There are more than 1 language specified, just keep the first one. |
279 *code = code->substr(0, coma_index); | 282 *code = code->substr(0, coma_index); |
280 } | 283 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // distinguish from English, and the language is one of well-known languages | 380 // distinguish from English, and the language is one of well-known languages |
378 // which often provide "en-*" meta information mistakenly. | 381 // which often provide "en-*" meta information mistakenly. |
379 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { | 382 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { |
380 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) | 383 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) |
381 return true; | 384 return true; |
382 } | 385 } |
383 return false; | 386 return false; |
384 } | 387 } |
385 | 388 |
386 } // namespace translate | 389 } // namespace translate |
OLD | NEW |