| Index: ui/base/l10n/l10n_util.cc
|
| diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc
|
| index 7515f3f6071663a878863e231022303f0f210e35..140ddc42a1043df63f3feaef06e913d3425a64a1 100644
|
| --- a/ui/base/l10n/l10n_util.cc
|
| +++ b/ui/base/l10n/l10n_util.cc
|
| @@ -303,6 +303,30 @@ struct AvailableLocalesTraits
|
| }
|
| };
|
|
|
| +// Extract language, country and variant, but ignore keywords. For example,
|
| +// en-US, ca@valencia, ca-ES@valencia.
|
| +std::string GetLocaleString(const icu::Locale& locale) {
|
| + const char* language = locale.getLanguage();
|
| + const char* country = locale.getCountry();
|
| + const char* variant = locale.getVariant();
|
| +
|
| + std::string result =
|
| + (language != NULL && *language != '\0') ? language : "und";
|
| +
|
| + if (country != NULL && *country != '\0') {
|
| + result += '-';
|
| + result += country;
|
| + }
|
| +
|
| + if (variant != NULL && *variant != '\0') {
|
| + std::string variant_str(variant);
|
| + base::StringToLowerASCII(&variant_str);
|
| + result += '@' + variant_str;
|
| + }
|
| +
|
| + return result;
|
| +}
|
| +
|
| base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits>
|
| g_available_locales = LAZY_INSTANCE_INITIALIZER;
|
|
|
| @@ -310,8 +334,18 @@ base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits>
|
|
|
| namespace l10n_util {
|
|
|
| +// Convert the ICU default locale to a string.
|
| +std::string GetConfiguredLocale() {
|
| + return GetLocaleString(icu::Locale::getDefault());
|
| +}
|
| +
|
| +// Convert the ICU canonicalized locale to a string.
|
| +std::string GetCanonicalLocale(const char* locale) {
|
| + return GetLocaleString(icu::Locale::createCanonical(locale));
|
| +}
|
| +
|
| std::string GetCanonicalLocale(const std::string& locale) {
|
| - return base::i18n::GetCanonicalLocale(locale.c_str());
|
| + return GetCanonicalLocale(locale.c_str());
|
| }
|
|
|
| std::string GetLanguage(const std::string& locale) {
|
| @@ -444,7 +478,7 @@ std::string GetApplicationLocaleInternal(const std::string& pref_locale) {
|
| std::back_inserter(candidates), &GetCanonicalLocale);
|
| } else {
|
| // If no override was set, defer to ICU
|
| - candidates.push_back(base::i18n::GetConfiguredLocale());
|
| + candidates.push_back(GetConfiguredLocale());
|
| }
|
|
|
| #elif defined(OS_ANDROID)
|
| @@ -464,7 +498,7 @@ std::string GetApplicationLocaleInternal(const std::string& pref_locale) {
|
| DCHECK(*languages); // At least one entry, "C", is guaranteed.
|
|
|
| for (; *languages != NULL; ++languages) {
|
| - candidates.push_back(base::i18n::GetCanonicalLocale(*languages));
|
| + candidates.push_back(GetCanonicalLocale(*languages));
|
| }
|
|
|
| #else
|
|
|