summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 01:50:22 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 01:50:22 +0000
commit41d52eff8b94a028b5a62c3e9b7541772a707bc9 (patch)
tree747b3b5e8110a0729b155098d3473b5b48cace95
parentbcff05af3d60df10a21e07751a14b95ce9e7f3d4 (diff)
downloadchromium_src-41d52eff8b94a028b5a62c3e9b7541772a707bc9.zip
chromium_src-41d52eff8b94a028b5a62c3e9b7541772a707bc9.tar.gz
chromium_src-41d52eff8b94a028b5a62c3e9b7541772a707bc9.tar.bz2
Add LanguageLibrary::GetLanguageCodeFromDescriptor().
This encapsulates differences between the language codes used in InputMethodDescriptor and Chrome's application locale codes. TEST=unit_tests BUG=crosbug.com/2336 Review URL: http://codereview.chromium.org/1611026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44436 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros/language_library.cc32
-rw-r--r--chrome/browser/chromeos/cros/language_library.h6
-rw-r--r--chrome/browser/chromeos/cros/language_library_test.cc11
3 files changed, 47 insertions, 2 deletions
diff --git a/chrome/browser/chromeos/cros/language_library.cc b/chrome/browser/chromeos/cros/language_library.cc
index 10b8c23..86464e4 100644
--- a/chrome/browser/chromeos/cros/language_library.cc
+++ b/chrome/browser/chromeos/cros/language_library.cc
@@ -103,8 +103,36 @@ std::string LanguageLibrary::NormalizeLanguageCode(
bool LanguageLibrary::IsKeyboardLayout(
const std::string& input_method_id) {
- const bool case_insensitive = false;
- return StartsWithASCII(input_method_id, "xkb:", case_insensitive);
+ const bool kCaseInsensitive = false;
+ return StartsWithASCII(input_method_id, "xkb:", kCaseInsensitive);
+}
+
+std::string LanguageLibrary::GetLanguageCodeFromDescriptor(
+ const InputMethodDescriptor& descriptor) {
+ // Special-case Chewing. Handle this as zh-TW, rather than zh.
+ if (descriptor.id == "chewing" &&
+ descriptor.language_code == "zh") {
+ return "zh-TW";
+ }
+
+ std::string language_code =
+ LanguageLibrary::NormalizeLanguageCode(descriptor.language_code);
+
+ // Add country codes to language codes of some XKB input methods to make
+ // these compatible with Chrome's application locale codes like "en-US".
+ // TODO(satorux): Maybe we need to handle "es" for "es-419".
+ if (IsKeyboardLayout(descriptor.id) &&
+ (language_code == "en" ||
+ language_code == "zh" ||
+ language_code == "pt")) {
+ std::vector<std::string> portions;
+ SplitString(descriptor.id, ':', &portions);
+ if (portions.size() >= 2 && !portions[1].empty()) {
+ language_code.append("-");
+ language_code.append(StringToUpperASCII(portions[1]));
+ }
+ }
+ return language_code;
}
LanguageLibraryImpl::LanguageLibraryImpl()
diff --git a/chrome/browser/chromeos/cros/language_library.h b/chrome/browser/chromeos/cros/language_library.h
index bf51a31..929e69e 100644
--- a/chrome/browser/chromeos/cros/language_library.h
+++ b/chrome/browser/chromeos/cros/language_library.h
@@ -96,6 +96,12 @@ class LanguageLibrary {
// Returns true if the given input method id is for a keyboard layout.
static bool IsKeyboardLayout(const std::string& input_method_id);
+
+ // Gets the language code from the given input method descriptor. This
+ // encapsulates differences between the language codes used in
+ // InputMethodDescriptor and Chrome's application locale codes.
+ static std::string GetLanguageCodeFromDescriptor(
+ const InputMethodDescriptor& descriptor);
};
// This class handles the interaction with the ChromeOS language library APIs.
diff --git a/chrome/browser/chromeos/cros/language_library_test.cc b/chrome/browser/chromeos/cros/language_library_test.cc
index 11df138..bf0d232 100644
--- a/chrome/browser/chromeos/cros/language_library_test.cc
+++ b/chrome/browser/chromeos/cros/language_library_test.cc
@@ -33,4 +33,15 @@ TEST(LanguageLibraryTest, IsKeyboardLayout) {
EXPECT_FALSE(LanguageLibrary::IsKeyboardLayout("anthy"));
}
+TEST(LanguageLibraryTest, GetLanguageCodeFromDescriptor) {
+ EXPECT_EQ("ja", LanguageLibrary::GetLanguageCodeFromDescriptor(
+ InputMethodDescriptor("anthy", "Anthy", "ja")));
+ EXPECT_EQ("zh-TW", LanguageLibrary::GetLanguageCodeFromDescriptor(
+ InputMethodDescriptor("chewing", "Chewing", "zh")));
+ EXPECT_EQ("en-US", LanguageLibrary::GetLanguageCodeFromDescriptor(
+ InputMethodDescriptor("xkb:us::eng", "USA", "eng")));
+ EXPECT_EQ("en-UK", LanguageLibrary::GetLanguageCodeFromDescriptor(
+ InputMethodDescriptor("xkb:uk::eng", "United Kingdom", "eng")));
+}
+
} // namespace chromeos