diff options
author | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-11 21:16:46 +0000 |
---|---|---|
committer | jshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-11 21:16:46 +0000 |
commit | 3117306367ccfee1595e668ffc1101979c4823e8 (patch) | |
tree | 58374e93e2281b3797c2cbb38955c6ccf3107964 /app | |
parent | ec3625e3d6de06cbb2bf79531af92eaf61c14bf8 (diff) | |
download | chromium_src-3117306367ccfee1595e668ffc1101979c4823e8.zip chromium_src-3117306367ccfee1595e668ffc1101979c4823e8.tar.gz chromium_src-3117306367ccfee1595e668ffc1101979c4823e8.tar.bz2 |
Maps our internal Chinese locale codes to those expected by the ICU API for
the display name of a locale and expected by Google (in case of 'nb vs no').
1. Map zh-CN and zh-TW to zh-Hans and zh-Hant in GetDisplay
2. Map nb to no before adding 'hl' param for Google services. This will be removed once Google begins to honor 'nb'.
3. While doing so, I found that language_combox_model.cc has the exactly the
same code as in l10n_util.cc and refactored it.
BUG=34531
TEST=1. app_unittest: L10nUt*.LocaleDispla*
2. See the bug 34531
3. On Windows, the language menu in
Options | Under the hood | Fonts & Language Menu | Language tab lists
'Chinese (Simplified Han)' and 'Chinese (Traditional Han)' for Simplified
Chinese and Traditional Chinese in English Chrome along with
Chinese names for those two languages. This is the behavior
without this CL and it should't change with the refactoring.
Review URL: http://codereview.chromium.org/596033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/l10n_util.cc | 24 | ||||
-rw-r--r-- | app/l10n_util.h | 8 | ||||
-rw-r--r-- | app/l10n_util_unittest.cc | 16 |
3 files changed, 43 insertions, 5 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc index 9f28842..1feb09d 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -524,9 +524,31 @@ std::string GetApplicationLocale(const std::wstring& pref_locale) { #endif // !defined(OS_MACOSX) } -string16 GetDisplayNameForLocale(const std::string& locale_code, +string16 GetDisplayNameForLocale(const std::string& locale, const std::string& display_locale, bool is_for_ui) { + std::string locale_code = locale; + // Internally, we use the language code of zh-CN and zh-TW, but we want the + // display names to be Chinese (Simplified) and Chinese (Traditional) instead + // of Chinese (China) and Chinese (Taiwan). To do that, we pass zh-Hans + // and zh-Hant to ICU. Even with this mapping, we'd get + // 'Chinese (Simplified Han)' and 'Chinese (Traditional Han)' in English and + // even longer results in other languages. Arguably, they're better than + // the current results : Chinese (China) / Chinese (Taiwan). + // TODO(jungshik): Do one of the following: + // 1. Special-case Chinese by getting the custom-translation for them + // 2. Recycle IDS_ENCODING_{SIMP,TRAD}_CHINESE. + // 3. Get translations for two directly from the ICU resouce bundle + // because they're not accessible with other any API. + // 4. Patch ICU to special-case zh-Hans/zh-Hant for us. + // #1 and #2 wouldn't work if display_locale != current UI locale although + // we can think of additional hack to work around the problem. + // #3 can be potentially expensive. + if (locale_code == "zh-CN") + locale_code = "zh-Hans"; + else if (locale_code == "zh-TW") + locale_code = "zh-Hant"; + UErrorCode error = U_ZERO_ERROR; const int buffer_size = 1024; diff --git a/app/l10n_util.h b/app/l10n_util.h index d75d357..8ed7596 100644 --- a/app/l10n_util.h +++ b/app/l10n_util.h @@ -54,14 +54,14 @@ bool IsLocaleSupportedByOS(const std::string& locale); // This method returns the display name of the locale code in |display_locale|. -// For example, for |locale_code| = "en-US" and |display_locale| = "en", -// it returns "English (United States)". To get the display name of -// |locale_code| in the UI language of Chrome, |display_locale| can be +// For example, for |locale| = "fr" and |display_locale| = "en", +// it returns "French". To get the display name of +// |locale| in the UI language of Chrome, |display_locale| can be // set to the return value of g_browser_process->GetApplicationLocale() // in the UI thread. // If |is_for_ui| is true, U+200F is appended so that it can be // rendered properly in a RTL Chrome. -string16 GetDisplayNameForLocale(const std::string& locale_code, +string16 GetDisplayNameForLocale(const std::string& locale, const std::string& display_locale, bool is_for_ui); diff --git a/app/l10n_util_unittest.cc b/app/l10n_util_unittest.cc index 693c586..bd55ff9 100644 --- a/app/l10n_util_unittest.cc +++ b/app/l10n_util_unittest.cc @@ -513,3 +513,19 @@ TEST_F(L10nUtilTest, UpperLower) { result = l10n_util::ToUpper(mixed); EXPECT_EQ(result, expected_upper); } + +TEST_F(L10nUtilTest, LocaleDisplayName) { + // TODO(jungshik): Make this test more extensive. + // Test zh-CN and zh-TW are treated as zh-Hans and zh-Hant. + string16 result = l10n_util::GetDisplayNameForLocale("zh-CN", "en", false); + EXPECT_EQ(result, ASCIIToUTF16("Chinese (Simplified Han)")); + + result = l10n_util::GetDisplayNameForLocale("zh-TW", "en", false); + EXPECT_EQ(result, ASCIIToUTF16("Chinese (Traditional Han)")); + + result = l10n_util::GetDisplayNameForLocale("pt-BR", "en", false); + EXPECT_EQ(result, ASCIIToUTF16("Portuguese (Brazil)")); + + result = l10n_util::GetDisplayNameForLocale("es-419", "en", false); + EXPECT_EQ(result, ASCIIToUTF16("Spanish (Latin America and the Caribbean)")); +} |