#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/translate/core/language_detection/language_detection_util.h"
#include <stddef.h>
#include <string_view>
#include "base/containers/fixed_flat_set.h"
#include "base/logging.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/metrics_hashes.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/language/core/common/language_util.h"
#include "components/translate/core/common/translate_constants.h"
#include "components/translate/core/common/translate_metrics.h"
#include "components/translate/core/language_detection/chinese_script_classifier.h"
#include "third_party/cld_3/src/src/nnet_language_identifier.h"
namespace {
struct SimilarLanguageCode { … };
const SimilarLanguageCode kSimilarLanguageCodes[] = …;
int GetSimilarLanguageGroupCode(const std::string& language) { … }
void ApplyLanguageCodeCorrection(std::string* code) { … }
std::string GetHTMLOrHTTPContentLanguage(const std::string& content_lang,
const std::string& html_lang) { … }
bool CanModelComplementSubCode(const std::string& page_language,
const std::string& model_detected_language) { … }
}
namespace translate {
std::string FilterDetectedLanguage(const std::string& utf8_text,
const std::string& detected_language,
bool is_detection_reliable) { … }
std::string DetermineTextLanguage(const std::string& utf8_text,
bool* is_model_reliable,
float& model_reliability_score) { … }
std::string DeterminePageLanguage(const std::string& code,
const std::string& html_lang,
const std::u16string& contents,
std::string* model_detected_language,
bool* is_model_reliable,
float& model_reliability_score) { … }
std::string DeterminePageLanguageNoModel(
const std::string& code,
const std::string& html_lang,
LanguageVerificationType language_verification_type) { … }
std::string DeterminePageLanguage(const std::string& code,
const std::string& html_lang,
const std::string& model_detected_language,
bool is_model_reliable) { … }
void CorrectLanguageCodeTypo(std::string* code) { … }
bool IsValidLanguageCode(const std::string& code) { … }
bool IsSameOrSimilarLanguages(const std::string& page_language,
const std::string& model_detected_language) { … }
bool IsServerWrongConfigurationLanguage(const std::string& language_code) { … }
bool MaybeServerWrongConfiguration(const std::string& page_language,
const std::string& model_detected_language) { … }
}