| Index: third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| diff --git a/third_party/libaddressinput/chromium/cpp/src/address_ui.cc b/third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| index c4eeb99c94e879914bd32ebd345747ca8b1c52b1..29ca3730d0356bd70d0039383fd1b2ad053881eb 100644
|
| --- a/third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| +++ b/third_party/libaddressinput/chromium/cpp/src/address_ui.cc
|
| @@ -17,6 +17,8 @@
|
| #include <libaddressinput/address_field.h>
|
| #include <libaddressinput/address_ui_component.h>
|
|
|
| +#include <algorithm>
|
| +#include <cstddef>
|
| #include <set>
|
| #include <string>
|
| #include <vector>
|
| @@ -25,6 +27,7 @@
|
| #include "grit/libaddressinput_strings.h"
|
| #include "region_data_constants.h"
|
| #include "rule.h"
|
| +#include "util.h"
|
|
|
| namespace i18n {
|
| namespace addressinput {
|
| @@ -58,6 +61,54 @@ int GetMessageIdForField(AddressField field,
|
| }
|
| }
|
|
|
| +// Returns the BCP 47 language code that should be used to format the address
|
| +// that the user entered.
|
| +//
|
| +// If the rule does not contain information about languages, then returns the
|
| +// UI language.
|
| +//
|
| +// If the UI language is either the default language for the country, one of the
|
| +// languages for rules, or one of the languages for address input, then returns
|
| +// this UI language. If there're no matches, then picks one of the languages in
|
| +// the rule and returns it.
|
| +//
|
| +// If |using_latin_format| is true and the UI language does not match any
|
| +// languages in the rule, then appends "-latn" to the normalized version of the
|
| +// language for the rule.
|
| +std::string GetComponentsLanguageCode(
|
| + const std::vector<std::string>& rule_languages,
|
| + const std::vector<std::string>& input_languages,
|
| + const std::string& norm_default_lang,
|
| + const std::string& norm_ui_lang,
|
| + const std::string& ui_lang,
|
| + bool using_latin_format) {
|
| + if (std::find(rule_languages.begin(), rule_languages.end(), norm_ui_lang) !=
|
| + rule_languages.end() ||
|
| + std::find(rule_languages.begin(), rule_languages.end(), ui_lang) !=
|
| + rule_languages.end() ||
|
| + std::find(input_languages.begin(), input_languages.end(), norm_ui_lang) !=
|
| + input_languages.end() ||
|
| + std::find(input_languages.begin(), input_languages.end(), ui_lang) !=
|
| + input_languages.end() ||
|
| + norm_default_lang == norm_ui_lang) {
|
| + return ui_lang;
|
| + }
|
| +
|
| + std::string rule_lang;
|
| + if (!norm_default_lang.empty()) {
|
| + rule_lang = norm_default_lang;
|
| + } else if (!rule_languages.empty()) {
|
| + rule_lang = rule_languages[0];
|
| + } else if (!input_languages.empty()) {
|
| + rule_lang = input_languages[0];
|
| + } else {
|
| + return ui_lang;
|
| + }
|
| +
|
| + return using_latin_format ? NormalizeLanguageCode(rule_lang) + "-latn"
|
| + : rule_lang;
|
| +}
|
| +
|
| } // namespace
|
|
|
| const std::vector<std::string>& GetRegionCodes() {
|
| @@ -65,7 +116,9 @@ const std::vector<std::string>& GetRegionCodes() {
|
| }
|
|
|
| std::vector<AddressUiComponent> BuildComponents(
|
| - const std::string& region_code) {
|
| + const std::string& region_code,
|
| + const std::string& ui_language_code,
|
| + std::string* components_language_code) {
|
| std::vector<AddressUiComponent> result;
|
|
|
| Rule rule;
|
| @@ -75,13 +128,28 @@ std::vector<AddressUiComponent> BuildComponents(
|
| return result;
|
| }
|
|
|
| + std::string norm_ui_lang = NormalizeLanguageCode(ui_language_code);
|
| + std::string norm_region_lang = NormalizeLanguageCode(rule.GetLanguage());
|
| +
|
| + const std::vector<std::vector<FormatElement> >& latin_format =
|
| + rule.GetLatinFormat();
|
| + bool use_latin_format =
|
| + norm_ui_lang != norm_region_lang && !latin_format.empty();
|
| + const std::vector<std::vector<FormatElement> >& format = use_latin_format
|
| + ? latin_format : rule.GetFormat();
|
| + if (components_language_code != NULL) {
|
| + *components_language_code = GetComponentsLanguageCode(
|
| + rule.GetLanguages(), rule.GetInputLanguages(), norm_region_lang,
|
| + norm_ui_lang, ui_language_code, use_latin_format);
|
| + }
|
| +
|
| // For avoiding showing an input field twice, when the field is displayed
|
| // twice on an envelope.
|
| std::set<AddressField> fields;
|
|
|
| for (std::vector<std::vector<FormatElement> >::const_iterator
|
| - line_it = rule.GetFormat().begin();
|
| - line_it != rule.GetFormat().end();
|
| + line_it = format.begin();
|
| + line_it != format.end();
|
| ++line_it) {
|
| int num_fields_this_row = 0;
|
| for (std::vector<FormatElement>::const_iterator element_it =
|
|
|