diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 09:11:26 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 09:11:26 +0000 |
commit | b7fe055464222bd5d1f2b6dc5a8fbbd83c2074bd (patch) | |
tree | bb213e2b67d5564cfbc7c5e456d0e1ecfa1992d5 /chrome/browser/chromeos | |
parent | 956e91264ebd09c023333752c345660083038b9d (diff) | |
download | chromium_src-b7fe055464222bd5d1f2b6dc5a8fbbd83c2074bd.zip chromium_src-b7fe055464222bd5d1f2b6dc5a8fbbd83c2074bd.tar.gz chromium_src-b7fe055464222bd5d1f2b6dc5a8fbbd83c2074bd.tar.bz2 |
Convert some spcial three-letter codes in NormalizeLanguageCode().
The conversion is necessary so we can show language names properly in UI.
TEST=unit_tests
BUG=none
Review URL: http://codereview.chromium.org/1607010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/cros/language_library.cc | 28 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/language_library_test.cc | 19 |
2 files changed, 38 insertions, 9 deletions
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc index b70ab60..6ccbf9f 100644 --- a/chrome/browser/chromeos/cros/language_library.cc +++ b/chrome/browser/chromeos/cros/language_library.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/cros/language_library.h" +#include "base/basictypes.h" #include "base/message_loop.h" #include "base/string_util.h" #include "chrome/browser/chrome_thread.h" @@ -39,13 +40,38 @@ bool FindAndUpdateProperty(const chromeos::ImeProperty& new_prop, return false; } +// There are some differences between ISO 639-2 (T) and ISO 639-2 B, and +// some language codes are not recognized by ICU (i.e. ICU cannot convert +// these codes to display names). Hence we convert these codes to ones +// that ICU recognize. +// +// See http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for details. +const char* kIso639VariantMapping[][2] = { + {"cze", "ces"}, + {"ger", "deu"}, + {"gre", "ell"}, + // "scr" is not a ISO 639 code. For some reason, evdev.xml uses "scr" as + // the language code for Croatian. + {"scr", "hrv"}, + {"rum", "ron"}, + {"slo", "slk"}, +}; + } // namespace namespace chromeos { std::string LanguageLibrary::NormalizeLanguageCode( const std::string& language_code) { - // We only handle two-letter codes here. + // Convert some language codes. See comments at kIso639VariantMapping. + if (language_code.size() == 3) { + for (size_t i = 0; i < arraysize(kIso639VariantMapping); ++i) { + if (language_code == kIso639VariantMapping[i][0]) { + return kIso639VariantMapping[i][1]; + } + } + } + // We only handle two-letter codes from here. // Some ibus engines return locale codes like "zh_CN" as language codes, // and we don't want to rewrite this to "zho". if (language_code.size() != 2) { diff --git a/chrome/browser/chromeos/cros/language_library_test.cc b/chrome/browser/chromeos/cros/language_library_test.cc index f921674..ade0f34 100644 --- a/chrome/browser/chromeos/cros/language_library_test.cc +++ b/chrome/browser/chromeos/cros/language_library_test.cc @@ -10,14 +10,17 @@ namespace chromeos { TEST(LanguageLibraryTest, NormalizeLanguageCode) { // TODO(yusukes): test all language codes that IBus provides. - EXPECT_EQ("jpn", - LanguageLibrary::NormalizeLanguageCode("ja")); - EXPECT_EQ("jpn", - LanguageLibrary::NormalizeLanguageCode("jpn")); - EXPECT_EQ("t", - LanguageLibrary::NormalizeLanguageCode("t")); - EXPECT_EQ("zh_CN", - LanguageLibrary::NormalizeLanguageCode("zh_CN")); + EXPECT_EQ("jpn", LanguageLibrary::NormalizeLanguageCode("ja")); + EXPECT_EQ("jpn", LanguageLibrary::NormalizeLanguageCode("jpn")); + EXPECT_EQ("t", LanguageLibrary::NormalizeLanguageCode("t")); + EXPECT_EQ("zh_CN", LanguageLibrary::NormalizeLanguageCode("zh_CN")); + // Special three-letter language codes. + EXPECT_EQ("ces", LanguageLibrary::NormalizeLanguageCode("cze")); + EXPECT_EQ("deu", LanguageLibrary::NormalizeLanguageCode("ger")); + EXPECT_EQ("ell", LanguageLibrary::NormalizeLanguageCode("gre")); + EXPECT_EQ("hrv", LanguageLibrary::NormalizeLanguageCode("scr")); + EXPECT_EQ("ron", LanguageLibrary::NormalizeLanguageCode("rum")); + EXPECT_EQ("slk", LanguageLibrary::NormalizeLanguageCode("slo")); } TEST(LanguageLibraryTest, IsKeyboardLayout) { |