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

Unified Diff: extensions/renderer/i18n_custom_bindings.cc

Issue 2359793003: Modifying language detection code (Closed)
Patch Set: Extending the comment about xx-Latn languages 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..34dd6c89c0f9be01558bf8098b37fab95dc18ce9 100644
--- a/extensions/renderer/i18n_custom_bindings.cc
+++ b/extensions/renderer/i18n_custom_bindings.cc
@@ -10,6 +10,7 @@
#include <vector>
#include "base/bind.h"
+#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
@@ -135,6 +136,7 @@ void InitDetectedLanguages(
LanguageDetectionResult* result) {
std::vector<std::unique_ptr<DetectedLanguage>>* detected_languages =
&result->languages;
+ DCHECK(detected_languages->empty());
bool* is_reliable = &result->is_reliable;
// is_reliable is set to "true", so that the reliability can be calculated by
@@ -144,20 +146,33 @@ void InitDetectedLanguages(
const chrome_lang_id::NNetLanguageIdentifier::Result& lang_result =
lang_results.at(i);
const std::string& language_code = lang_result.language;
+
+ // If a language is kUnknown, then the remaining ones are also 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;
}
+ // The list of languages supported by CLD3 is saved in kLanguageNames
+ // in the following file:
+ // //src/third_party/cld_3/src/src/task_context_params.cc
+ // Among the entries in this list are transliterated languages
+ // (called xx-Latn) which don't belong to the spec ISO639-1 used by
+ // the previous model, CLD2. Thus, to maintain backwards compatibility,
+ // xx-Latn predictions are ignored for now.
+ if (base::EndsWith(language_code, "-Latn",
+ base::CompareCase::INSENSITIVE_ASCII)) {
+ 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