Chromium Code Reviews| Index: ui/base/l10n/l10n_util.cc |
| diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc |
| index 6cf460883531f038d5435dcb99117a3b7d56e616..9ea69c1dae845e7499a79b14a47e17b7fd23ea19 100644 |
| --- a/ui/base/l10n/l10n_util.cc |
| +++ b/ui/base/l10n/l10n_util.cc |
| @@ -27,6 +27,10 @@ |
| #include "unicode/rbbi.h" |
| #include "unicode/uloc.h" |
| +#if defined(OS_ANDROID) |
| +#include "base/android/locale_utils.h" |
| +#endif |
| + |
| #if defined(OS_LINUX) |
| #include <glib.h> |
| #endif |
| @@ -474,26 +478,49 @@ string16 GetDisplayNameForLocale(const std::string& locale, |
| // #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") |
| + bool is_zh = false; |
| + if (locale_code == "zh-CN") { |
| locale_code = "zh-Hans"; |
| - else if (locale_code == "zh-TW") |
| + is_zh = true; |
| + } else if (locale_code == "zh-TW") { |
| locale_code = "zh-Hant"; |
| - |
| - UErrorCode error = U_ZERO_ERROR; |
| - const int kBufferSize = 1024; |
| + is_zh = true; |
| + } |
| string16 display_name; |
| - int actual_size = uloc_getDisplayName(locale_code.c_str(), |
| - display_locale.c_str(), |
| - WriteInto(&display_name, kBufferSize), kBufferSize - 1, &error); |
| - DCHECK(U_SUCCESS(error)); |
| - display_name.resize(actual_size); |
| +#if defined(OS_ANDROID) |
| + // Use Java API to get locale display name so that we can remove the most of |
| + // the lang data from icu data to reduce binary size, except for zh-Hans and |
| + // zh-Hant because Java API doesn't support scripts. |
| + if (!is_zh) { |
| + display_name = base::android::GetDisplayNameForLocale(locale_code, |
| + display_locale); |
| + } else |
| +#endif |
| + { |
| + UErrorCode error = U_ZERO_ERROR; |
| + const int kBufferSize = 1024; |
| + |
| + string16 display_name; |
| + int actual_size = uloc_getDisplayName(locale_code.c_str(), |
| + display_locale.c_str(), |
| + WriteInto(&display_name, kBufferSize), kBufferSize - 1, &error); |
| + DCHECK(U_SUCCESS(error)); |
| + display_name.resize(actual_size); |
| + } |
| + |
| // Add an RTL mark so parentheses are properly placed. |
| if (is_for_ui && base::i18n::IsRTL()) |
| display_name.push_back(static_cast<char16>(base::i18n::kRightToLeftMark)); |
| return display_name; |
| } |
| +string16 GetDisplayNameForCountry(const std::string& country_code, |
| + const std::string& display_locale, |
| + bool is_for_ui) { |
| + return GetDisplayNameForLocale("_" + country_code, display_locale, is_for_ui); |
|
sky
2012/04/25 21:06:43
This hardly seems worth adding a new function for.
Xianzhu
2012/04/25 22:36:23
Both ICU uloc_getDisplayName and base::android::Ge
|
| +} |
| + |
| std::string NormalizeLocale(const std::string& locale) { |
| std::string normalized_locale(locale); |
| std::replace(normalized_locale.begin(), normalized_locale.end(), '-', '_'); |