Commit b81b0790 authored by Christoph Schwering's avatar Christoph Schwering Committed by Commit Bot

[Autofill][Translate] Added documentation of source language code.

Bug: 1142413, 1150277
Change-Id: I19a5f90933e5da7e9d2ea79e7c1fff7c48002cd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550383Reviewed-by: default avatarMegan Jablonski <megjablon@chromium.org>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Christoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#829867}
parent e5f4441c
...@@ -9,14 +9,15 @@ ...@@ -9,14 +9,15 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/logging.h"
#include "base/ranges/algorithm.h" #include "base/ranges/algorithm.h"
#include "base/types/strong_alias.h" #include "base/types/strong_alias.h"
namespace autofill { namespace autofill {
// A LanguageCode is a two-letter lowercase abbreviation according to ISO 639-1 // Following the implicit conventions in //components/translate, a LanguageCode
// or "und", which is the ISO 639-2 code for "undetermined". // in is a lowercase alphabetic string of length up to 3, or "zh-CN", or
// "zh-TW". A non-exhaustive list of common values is
// translate::kDefaultSupportedLanguages.
class LanguageCode class LanguageCode
: public base::StrongAlias<class LanguageCodeTag, std::string> { : public base::StrongAlias<class LanguageCodeTag, std::string> {
private: private:
...@@ -33,10 +34,8 @@ class LanguageCode ...@@ -33,10 +34,8 @@ class LanguageCode
private: private:
void Check() { void Check() {
LOG_IF(ERROR, DCHECK((length() <= 3 && base::ranges::all_of(value(), &islower)) ||
!(empty() || value() == "zh-CN" || value() == "zh-TW")
(base::ranges::all_of(value(), &islower) && length() == 2) ||
value() == "und" || value() == "zh-CN" || value() == "zh-TW"))
<< "Unexpected language code '" << value() << "'"; << "Unexpected language code '" << value() << "'";
} }
}; };
......
...@@ -52,11 +52,15 @@ class LanguageState { ...@@ -52,11 +52,15 @@ class LanguageState {
// Returns true if the current page in the associated tab has been translated. // Returns true if the current page in the associated tab has been translated.
bool IsPageTranslated() const { return original_lang_ != current_lang_; } bool IsPageTranslated() const { return original_lang_ != current_lang_; }
void SetOriginalLanguage(const std::string& language); // Returns the original language represented as a lowercase alphabetic string
// of length 0 to 3 or "zh-CN" or "zh-TW".
const std::string& original_language() const { return original_lang_; } const std::string& original_language() const { return original_lang_; }
void SetOriginalLanguage(const std::string& language);
void SetCurrentLanguage(const std::string& language); // Returns the current language represented as a lowercase alphabetic string
// of length 0 to 3 or "zh-CN" or "zh-TW".
const std::string& current_language() const { return current_lang_; } const std::string& current_language() const { return current_lang_; }
void SetCurrentLanguage(const std::string& language);
bool page_needs_translation() const { return page_needs_translation_; } bool page_needs_translation() const { return page_needs_translation_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment