summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-15 17:35:11 +0000
committerjshin@chromium.org <jshin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-15 17:35:11 +0000
commitd88453afb9292607a16321e23785e5ee2417f776 (patch)
tree31073350c0d66d01aa1499ce1a2d67b63f056de6
parent6b7e090e931edb1cb31a53ca9852ffd0ba3ee7ea (diff)
downloadchromium_src-d88453afb9292607a16321e23785e5ee2417f776.zip
chromium_src-d88453afb9292607a16321e23785e5ee2417f776.tar.gz
chromium_src-d88453afb9292607a16321e23785e5ee2417f776.tar.bz2
UI language list fix.
30+ minimally populated locales were added to our ICU data. As a result, GetAvailableLocale() used whenconstructing the UI language menu in Chrome list languages Chrome is not localized to. 1. Add IsPartiallyPopulatedLocale() to l10n_util (anonymous namespace) and skip those locales when constructing the locale list. 2. Add 'Hawaiian', 'Oromo' and 'Hausa' to the Accept-Language list. I'll add other languages to the trunk later. BUG=21119 (http://crbug.com/21119), 19329 ( http://crbug.com/19329 ) TEST=1. Launch Chrome and go to Options | "Advanced" | Languages & Fonts menu | Languages tab | Google Chrome language. The list of languages to choose from should contain only languages Chrome is localized to (40 + 1 + 8) and should not contain languages like Hawaian, Belarusian. 2. Accept-Language list should contain 3 new languages added (Hawaiian, Oromo and Hausa) Review URL: http://codereview.chromium.org/193027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26230 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/l10n_util.cc47
1 files changed, 36 insertions, 11 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index a58defb..2dd3cf2 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -87,6 +87,8 @@ static const char* const kAcceptLanguageList[] = {
"gl", // Galician
"gn", // Guarani
"gu", // Gujarati
+ "ha", // Hausa
+ "haw", // Hawaiian
"he", // Hebrew
"hi", // Hindi
"hr", // Croatian
@@ -125,6 +127,7 @@ static const char* const kAcceptLanguageList[] = {
"nn", // Norwegian (Nynorsk)
"no", // Norwegian
"oc", // Occitan
+ "om", // Oromo
"or", // Oriya
"pa", // Punjabi
"pl", // Polish
@@ -256,6 +259,31 @@ bool IsDuplicateName(const std::string& locale_name) {
return false;
}
+bool IsLocaleNameTranslated(const char* locale,
+ const std::string& display_locale) {
+ string16 display_name =
+ l10n_util::GetDisplayNameForLocale(locale, display_locale, false);
+ // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not
+ // uloc_getDisplayName returns the actual translation or the default
+ // value (locale code), we have to rely on this hack to tell whether
+ // the translation is available or not. If ICU doesn't have a translated
+ // name for this locale, GetDisplayNameForLocale will just return the
+ // locale code.
+ return !IsStringASCII(display_name) || UTF16ToASCII(display_name) != locale;
+}
+
+// We added 30+ minimally populated locales with only a few entries
+// (exemplar character set, script, writing direction and its own
+// lanaguage name). These locales have to be distinguished from the
+// fully populated locales to which Chrome is localized.
+bool IsLocalePartiallyPopulated(const std::string& locale_name) {
+ // For partially populated locales, even the translation for "English"
+ // is not available. A more robust/elegant way to check is to add a special
+ // field (say, 'isPartial' to our version of ICU locale files) and
+ // check its value, but this hack seems to work well.
+ return !IsLocaleNameTranslated("en", locale_name);
+}
+
bool IsLocaleAvailable(const std::string& locale,
const FilePath& locale_path) {
// If locale has any illegal characters in it, we don't want to try to
@@ -865,6 +893,10 @@ const std::vector<std::string>& GetAvailableLocales() {
// Filter out the names that have aliases.
if (IsDuplicateName(locale_name))
continue;
+ // Filter out locales for which we have only partially populated data
+ // and to which Chrome is not localized.
+ if (IsLocalePartiallyPopulated(locale_name))
+ continue;
if (!IsLocaleSupportedByOS(locale_name))
continue;
// Normalize underscores to hyphens because that's what our locale files
@@ -889,17 +921,10 @@ const std::vector<std::string>& GetAvailableLocales() {
void GetAcceptLanguagesForLocale(const std::string& display_locale,
std::vector<std::string>* locale_codes) {
for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) {
- string16 display_name =
- l10n_util::GetDisplayNameForLocale(kAcceptLanguageList[i],
- display_locale, false);
- // This is a hack. If ICU doesn't have a translated name for
- // this language, GetDisplayNameForLocale will just return the
- // language code. In that case, we skip it.
- // TODO(jungshik) : Put them at the of the list with language codes
- // enclosed by brackets.
- if (IsStringASCII(display_name) &&
- UTF16ToASCII(display_name) == kAcceptLanguageList[i])
- continue;
+ if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale))
+ // TODO(jungshik) : Put them at the of the list with language codes
+ // enclosed by brackets instead of skipping.
+ continue;
locale_codes->push_back(kAcceptLanguageList[i]);
}
}