Skip to content

Commit

Permalink
When resolving the locale, use pt-PT for unsupported pt-**
Browse files Browse the repository at this point in the history
This also maps "pt" -> "pt-BR", and "zh"->"zh-CN".

Chrome has two .pak files for Portuguese: pt-PT and pt-BR. This is
different from most locales in that there is no plain "pt.pak", which
would be selected by normal locale resolving logic. The other exceptions
are zh and en, both of which already have special-case fallback logic
(with the exception of a bare "zh", which this CL addresses).

This change adds equivalent fallback logic for pt-PT.

BUG=691594

Review-Url: https://codereview.chromium.org/2733303002
Cr-Commit-Position: refs/heads/master@{#455326}
(cherry picked from commit 6f16f90)

Review-Url: https://codereview.chromium.org/2737553006 .
Cr-Commit-Position: refs/branch-heads/3029@{#57}
Cr-Branched-From: 939b32e-refs/heads/master@{#454471}
  • Loading branch information
agrieve committed Mar 8, 2017
1 parent 93e9aa4 commit f2865c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
11 changes: 7 additions & 4 deletions ui/base/l10n/l10n_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down Expand Up @@ -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)) {
Expand Down
35 changes: 22 additions & 13 deletions ui/base/l10n/l10n_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit f2865c1

Please sign in to comment.