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

Unified Diff: extensions/renderer/i18n_custom_bindings.cc

Issue 2359793003: Modifying language detection code (Closed)
Patch Set: Modifying the bindings code to ignore xx-Latn predictions Created 4 years, 3 months 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 | « components/translate/core/language_detection/language_detection_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/i18n_custom_bindings.cc
diff --git a/extensions/renderer/i18n_custom_bindings.cc b/extensions/renderer/i18n_custom_bindings.cc
index 7799d9d01a14917df75658b4d8434e471ba9d662..b7366f6d1ce677ca50fe56fc11d031bf8a0550aa 100644
--- a/extensions/renderer/i18n_custom_bindings.cc
+++ b/extensions/renderer/i18n_custom_bindings.cc
@@ -135,6 +135,7 @@ void InitDetectedLanguages(
LanguageDetectionResult* result) {
std::vector<std::unique_ptr<DetectedLanguage>>* detected_languages =
&result->languages;
+ detected_languages->clear();
Devlin 2016/09/27 18:34:42 Isn't this always the case? Could we DCHECK(detec
Anton Bakalov 2016/09/27 20:00:48 Done.
bool* is_reliable = &result->is_reliable;
// is_reliable is set to "true", so that the reliability can be calculated by
@@ -144,20 +145,31 @@ void InitDetectedLanguages(
const chrome_lang_id::NNetLanguageIdentifier::Result& lang_result =
lang_results.at(i);
const std::string& language_code = lang_result.language;
+
+ // If the first language is kUnknown, then all languages are kUnknown.
if (language_code == chrome_lang_id::NNetLanguageIdentifier::kUnknown) {
- // If the first language is kUnknown, then all languages are kUnknown.
- // Thus, is_reliable is set to "false".
- if (i == 0) {
- *is_reliable = false;
- }
break;
}
+ // Ignore languages that are currently not supported.
Devlin 2016/09/27 18:34:42 Can we expand this comment to include why these ar
Anton Bakalov 2016/09/27 20:00:48 Done.
+ if (language_code == "bg-Latn" ||
+ language_code == "el-Latn" ||
+ language_code == "hi-Latn" ||
+ language_code == "ja-Latn" ||
+ language_code == "ru-Latn" ||
+ language_code == "zh-Latn") {
+ continue;
+ }
+
*is_reliable = *is_reliable && lang_result.is_reliable;
const int percent = static_cast<int>(100 * lang_result.proportion);
detected_languages->push_back(
base::MakeUnique<DetectedLanguage>(language_code, percent));
}
+
+ if (detected_languages->empty()) {
+ *is_reliable = false;
+ }
}
#else
# error "CLD_VERSION must be 2 or 3"
« no previous file with comments | « components/translate/core/language_detection/language_detection_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698