diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc index ad0ad0ed9d12..440ab1a04d4d 100644 --- a/ui/base/l10n/l10n_util.cc +++ b/ui/base/l10n/l10n_util.cc @@ -357,6 +357,10 @@ bool CheckAndResolveLocale(const std::string& locale, if (base::LowerCaseEqualsASCII(lang, "es") && !base::LowerCaseEqualsASCII(region, "es")) { tmp_locale.append("-419"); + } else if (base::LowerCaseEqualsASCII(lang, "pt")) { + // Map pt-RR other than pt-BR to pt-PT. Note that "pt" by itself maps to + // pt-BR (logic below). + tmp_locale.append("-PT"); } else if (base::LowerCaseEqualsASCII(lang, "zh")) { // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. if (base::LowerCaseEqualsASCII(region, "hk") || @@ -387,14 +391,13 @@ bool CheckAndResolveLocale(const std::string& locale, } // Google updater uses no, tl, iw and en for our nb, fil, he, and en-US. + // Note that pt-RR is mapped to pt-PT above, but we want pt -> pt-BR here. struct { const char* source; const char* dest; } alias_map[] = { - {"no", "nb"}, - {"tl", "fil"}, - {"iw", "he"}, - {"en", "en-US"}, + {"en", "en-US"}, {"iw", "he"}, {"no", "nb"}, + {"pt", "pt-BR"}, {"tl", "fil"}, {"zh", "zh-CN"}, }; for (const auto& alias : alias_map) { if (base::LowerCaseEqualsASCII(lang, alias.source)) { diff --git a/ui/base/l10n/l10n_util_unittest.cc b/ui/base/l10n/l10n_util_unittest.cc index ab88a40ccb37..ee81f036888f 100644 --- a/ui/base/l10n/l10n_util_unittest.cc +++ b/ui/base/l10n/l10n_util_unittest.cc @@ -113,19 +113,8 @@ TEST_F(L10nUtilTest, GetAppLocale) { ASSERT_TRUE(PathService::Get(ui::DIR_LOCALES, &new_locale_dir)); // Make fake locale files. std::string filenames[] = { - "en-US", - "en-GB", - "fr", - "es-419", - "es", - "zh-TW", - "zh-CN", - "he", - "fil", - "nb", - "am", - "ca", - "ca@valencia", + "am", "ca", "ca@valencia", "en-GB", "en-US", "es", "es-419", "fil", + "fr", "he", "nb", "pt-BR", "pt-PT", "zh-CN", "zh-TW", }; for (size_t i = 0; i < arraysize(filenames); ++i) { @@ -267,6 +256,22 @@ TEST_F(L10nUtilTest, GetAppLocale) { EXPECT_EQ("es", l10n_util::GetApplicationLocale(std::string())); EXPECT_STREQ("es", icu::Locale::getDefault().getLanguage()); + SetDefaultLocaleForTest("pt-PT", env.get()); + EXPECT_EQ("pt-PT", l10n_util::GetApplicationLocale(std::string())); + EXPECT_STREQ("pt", icu::Locale::getDefault().getLanguage()); + + SetDefaultLocaleForTest("pt-BR", env.get()); + EXPECT_EQ("pt-BR", l10n_util::GetApplicationLocale(std::string())); + EXPECT_STREQ("pt", icu::Locale::getDefault().getLanguage()); + + SetDefaultLocaleForTest("pt-AO", env.get()); + EXPECT_EQ("pt-PT", l10n_util::GetApplicationLocale(std::string())); + EXPECT_STREQ("pt", icu::Locale::getDefault().getLanguage()); + + SetDefaultLocaleForTest("pt", env.get()); + EXPECT_EQ("pt-BR", l10n_util::GetApplicationLocale(std::string())); + EXPECT_STREQ("pt", icu::Locale::getDefault().getLanguage()); + SetDefaultLocaleForTest("zh-HK", env.get()); EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(std::string())); EXPECT_STREQ("zh", icu::Locale::getDefault().getLanguage()); @@ -279,6 +284,10 @@ TEST_F(L10nUtilTest, GetAppLocale) { EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(std::string())); EXPECT_STREQ("zh", icu::Locale::getDefault().getLanguage()); + SetDefaultLocaleForTest("zh", env.get()); + EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(std::string())); + EXPECT_STREQ("zh", icu::Locale::getDefault().getLanguage()); + SetDefaultLocaleForTest("en-CA", env.get()); EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(std::string())); EXPECT_STREQ("en", icu::Locale::getDefault().getLanguage());