diff options
-rw-r--r-- | chrome/common/l10n_util.cc | 44 | ||||
-rw-r--r-- | chrome/common/l10n_util_unittest.cc | 24 | ||||
-rw-r--r-- | chrome/installer/util/l10n_string_util.cc | 7 |
3 files changed, 67 insertions, 8 deletions
diff --git a/chrome/common/l10n_util.cc b/chrome/common/l10n_util.cc index fa93074..5c6e74b 100644 --- a/chrome/common/l10n_util.cc +++ b/chrome/common/l10n_util.cc @@ -134,7 +134,8 @@ bool IsDuplicateName(const std::string& locale_name) { return false; } -bool IsLocaleAvailable(const std::wstring& locale, const std::wstring& locale_path) { +bool IsLocaleAvailable(const std::wstring& locale, + const std::wstring& locale_path) { std::wstring test_locale = locale; // If locale has any illegal characters in it, we don't want to try to // load it because it may be pointing outside the locale dll directory. @@ -155,11 +156,8 @@ bool CheckAndResolveLocale(const std::wstring& locale, return true; } // If the locale matches language but not country, use that instead. - // TODO(jungshik) : we need a more extensive resolution (aliasing, - // contraction/expansion) to take care of various edge cases - // (zh-{HK,SG,MK}, en => en-US, es => es-{ES,419}). - // Also, this does not do anything about languages that Chrome - // currently does not support but available on Windows. We fall + // TODO(jungshik) : Nothing is done about languages that Chrome + // does not support but available on Windows. We fall // back to en-US in GetApplicationLocale so that it's a not critical, // but we can do better. std::wstring::size_type hyphen_pos = locale.find(L'-'); @@ -167,14 +165,46 @@ bool CheckAndResolveLocale(const std::wstring& locale, std::wstring lang(locale, 0, hyphen_pos); std::wstring region(locale, hyphen_pos + 1); std::wstring tmp_locale(lang); - // Map es-RR other than es-ES to es-419 (Chrome's Latin American Spanish locale). + // Map es-RR other than es-ES to es-419 (Chrome's Latin American + // Spanish locale). if (LowerCaseEqualsASCII(lang, "es") && !LowerCaseEqualsASCII(region, "es")) tmp_locale.append(L"-419"); + else if (LowerCaseEqualsASCII(lang, "zh")) { + // Map zh-HK and zh-MK to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. + if (LowerCaseEqualsASCII(region, "hk") || + LowerCaseEqualsASCII(region, "mk")) { + tmp_locale.append(L"-TW"); + } else { + tmp_locale.append(L"-CN"); + } + } if (IsLocaleAvailable(tmp_locale, locale_path)) { resolved_locale->swap(tmp_locale); return true; } } + + // Google updater uses no, iw and en for our nb, he, and en-US. + // We need to map them to our codes. + struct { + const char* source; + const wchar_t* dest;} alias_map[] = { + {"no", L"nb"}, + {"tl", L"fil"}, + {"iw", L"he"}, + {"en", L"en-US"}, + }; + + for (int i = 0; i < arraysize(alias_map); ++i) { + if (LowerCaseEqualsASCII(locale, alias_map[i].source)) { + std::wstring tmp_locale(alias_map[i].dest); + if (IsLocaleAvailable(tmp_locale, locale_path)) { + resolved_locale->swap(tmp_locale); + return true; + } + } + } + return false; } diff --git a/chrome/common/l10n_util_unittest.cc b/chrome/common/l10n_util_unittest.cc index 9b09037..ee14f23 100644 --- a/chrome/common/l10n_util_unittest.cc +++ b/chrome/common/l10n_util_unittest.cc @@ -77,6 +77,11 @@ TEST(L10nUtilTest, GetAppLocale) { L"fr.dll", L"es-419.dll", L"es.dll", + L"zh-TW.dll", + L"zh-CN.dll", + L"he.dll", + L"fil.dll", + L"nb.dll", }; for (size_t i = 0; i < arraysize(filenames); ++i) { std::wstring filename = new_locale_dir; @@ -102,6 +107,12 @@ TEST(L10nUtilTest, GetAppLocale) { SetICUDefaultLocale(L"en-US"); EXPECT_EQ(L"fr", l10n_util::GetApplicationLocale(L"fr")); EXPECT_EQ(L"fr", l10n_util::GetApplicationLocale(L"fr-CA")); + + SetICUDefaultLocale(L"en-US"); + // Aliases iw, no, tl to he, nb, fil. + EXPECT_EQ(L"he", l10n_util::GetApplicationLocale(L"iw")); + EXPECT_EQ(L"nb", l10n_util::GetApplicationLocale(L"no")); + EXPECT_EQ(L"fil", l10n_util::GetApplicationLocale(L"tl")); // es-419 and es-XX (where XX is not Spain) should be // mapped to es-419 (Latin American Spanish). EXPECT_EQ(L"es-419", l10n_util::GetApplicationLocale(L"es-419")); @@ -121,6 +132,19 @@ TEST(L10nUtilTest, GetAppLocale) { SetICUDefaultLocale(L"es"); EXPECT_EQ(L"es", l10n_util::GetApplicationLocale(L"")); + SetICUDefaultLocale(L"zh-HK"); + EXPECT_EQ(L"zh-TW", l10n_util::GetApplicationLocale(L"")); + EXPECT_EQ(L"zh-CN", l10n_util::GetApplicationLocale(L"zh-CN")); + + SetICUDefaultLocale(L"zh-MK"); + EXPECT_EQ(L"zh-TW", l10n_util::GetApplicationLocale(L"")); + + SetICUDefaultLocale(L"zh-SG"); + EXPECT_EQ(L"zh-CN", l10n_util::GetApplicationLocale(L"")); + + SetICUDefaultLocale(L"he"); + EXPECT_EQ(L"en-US", l10n_util::GetApplicationLocale(L"en")); + // Clean up. PathService::Override(chrome::DIR_LOCALES, orig_locale_dir); file_util::Delete(new_locale_dir, true); diff --git a/chrome/installer/util/l10n_string_util.cc b/chrome/installer/util/l10n_string_util.cc index dba8459..a7c636d 100644 --- a/chrome/installer/util/l10n_string_util.cc +++ b/chrome/installer/util/l10n_string_util.cc @@ -50,7 +50,7 @@ std::wstring GetSystemLanguage() { language.append(L"-pt"); } } else if (L"zh" == language) { - if (L"tw" == country) { + if (L"tw" == country || L"mk" == country || L"hk" == country) { language.append(L"-tw"); } else { language.append(L"-cn"); @@ -91,6 +91,8 @@ int GetLanguageOffset(const std::wstring& language) { offset_map[L"hu"] = IDS_L10N_OFFSET_HU; offset_map[L"id"] = IDS_L10N_OFFSET_ID; offset_map[L"it"] = IDS_L10N_OFFSET_IT; + // Google web properties use iw for he. Handle both just to be safe. + offset_map[L"iw"] = IDS_L10N_OFFSET_HE; offset_map[L"ja"] = IDS_L10N_OFFSET_JA; offset_map[L"ko"] = IDS_L10N_OFFSET_KO; offset_map[L"lt"] = IDS_L10N_OFFSET_LT; @@ -109,6 +111,9 @@ int GetLanguageOffset(const std::wstring& language) { offset_map[L"sr"] = IDS_L10N_OFFSET_SR; offset_map[L"sv"] = IDS_L10N_OFFSET_SV; offset_map[L"th"] = IDS_L10N_OFFSET_TH; + // Some Google web properties use tl for fil. Handle both just to be safe. + // They're not completely identical, but alias it here. + offset_map[L"tl"] = IDS_L10N_OFFSET_FIL; offset_map[L"tr"] = IDS_L10N_OFFSET_TR; offset_map[L"uk"] = IDS_L10N_OFFSET_UK; offset_map[L"vi"] = IDS_L10N_OFFSET_VI; |