| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/core/language_detection/language_detection_util.h
" | 5 #include "components/translate/core/language_detection/language_detection_util.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 pred_lang_hash); | 190 pred_lang_hash); |
| 191 if (predicted_language != chrome_lang_id::NNetLanguageIdentifier::kUnknown) { | 191 if (predicted_language != chrome_lang_id::NNetLanguageIdentifier::kUnknown) { |
| 192 UMA_HISTOGRAM_PERCENTAGE("Translate.CLD3.LanguagePercentage", | 192 UMA_HISTOGRAM_PERCENTAGE("Translate.CLD3.LanguagePercentage", |
| 193 static_cast<int>(100 * lang_id_result.proportion)); | 193 static_cast<int>(100 * lang_id_result.proportion)); |
| 194 } | 194 } |
| 195 | 195 |
| 196 if (is_cld_reliable != NULL) { | 196 if (is_cld_reliable != NULL) { |
| 197 *is_cld_reliable = prediction_reliable; | 197 *is_cld_reliable = prediction_reliable; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Ignore unreliable, "unknown", and xx-Latn predictions that are currently |
| 201 // not supported. |
| 200 if (prediction_reliable && | 202 if (prediction_reliable && |
| 203 predicted_language != "bg-Latn" && |
| 204 predicted_language != "el-Latn" && |
| 205 predicted_language != "ja-Latn" && |
| 206 predicted_language != "ru-Latn" && |
| 207 predicted_language != "zh-Latn" && |
| 201 predicted_language != | 208 predicted_language != |
| 202 chrome_lang_id::NNetLanguageIdentifier::kUnknown) { | 209 chrome_lang_id::NNetLanguageIdentifier::kUnknown) { |
| 203 // CLD3 returns 'zh' for Chinese but Translate doesn't accept it. Thus, | 210 // CLD3 returns 'zh' for Chinese but Translate doesn't accept it. Thus, |
| 204 // analogously to CLD2, 'zh-CN' is returned instead. | 211 // analogously to CLD2, 'zh-CN' is returned instead. |
| 205 if (predicted_language == "zh") { | 212 if (predicted_language == "zh") { |
| 206 language = "zh-CN"; | 213 language = "zh-CN"; |
| 207 } else { | 214 } else { |
| 208 language = predicted_language; | 215 language = predicted_language; |
| 209 } | 216 } |
| 210 } | 217 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // distinguish from English, and the language is one of well-known languages | 425 // distinguish from English, and the language is one of well-known languages |
| 419 // which often provide "en-*" meta information mistakenly. | 426 // which often provide "en-*" meta information mistakenly. |
| 420 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { | 427 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { |
| 421 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) | 428 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) |
| 422 return true; | 429 return true; |
| 423 } | 430 } |
| 424 return false; | 431 return false; |
| 425 } | 432 } |
| 426 | 433 |
| 427 } // namespace translate | 434 } // namespace translate |
| OLD | NEW |