Commit a45a20c9 authored by kochi@chromium.org's avatar kochi@chromium.org

Remove redundant "keyboard layout" suffix and fix redundant language display.

This issue is two-fold:

1) Remove "keyboard layout"-suffix from layouts
2) Do not show language name if obvious

For 1, basically I removed the suffix from keyboard layout names.
There are 2 exceptions:
 * For Japanese, to avoid confusion between Jpaanese input methods and
   Japanese keyboard layout, the suffix is intentionally kept.
 * For keyboard layouts used for Dutch, French and German,
   the suffix is kept (see below for the reason).

For 2,
* for non-ambiguous languages (do not have multiple input methods or layouts),
  show input method name or layout name
* for ambiguous languages
  - show keyboard layout or input method name without language name for
    other languages (as their layout name or input method name explicitly
    or implicitly imply language name)
  - show "language - layout" pair for Dutch, French and German
    (They share "Belgian" keyboard layout in common, showing only "Belgian"
    is ambiguous about language)

BUG=chromium-os:5804
TEST=./unit_tests --gtest_filter="LanguageMenu*" and manually check on ChromeOS device whether the menu text and notification menu are displayed as expected.

Review URL: http://codereview.chromium.org/3185020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57304 0039d316-1c4b-4281-b951-d872f2087c98
parent 0f403b49
......@@ -9181,61 +9181,61 @@ Keep your key file in a safe place. You will need it to create new versions of y
Japanese keyboard layout
</message>
<message name="IDS_STATUSBAR_LAYOUT_SLOVENIA" desc="In the language menu button, this shows the input mode.">
Sloveniain keyboard layout
Sloveniain
</message>
<message name="IDS_STATUSBAR_LAYOUT_GERMANY" desc="In the language menu button, this shows the input mode.">
German keyboard layout
</message>
<message name="IDS_STATUSBAR_LAYOUT_ITALY" desc="In the language menu button, this shows the input mode.">
Italian keyboard layout
Italian
</message>
<message name="IDS_STATUSBAR_LAYOUT_ESTONIA" desc="In the language menu button, this shows the input mode.">
Estonian keyboard layout
Estonian
</message>
<message name="IDS_STATUSBAR_LAYOUT_HUNGARY" desc="In the language menu button, this shows the input mode.">
Hungarian keyboard layout
Hungarian
</message>
<message name="IDS_STATUSBAR_LAYOUT_POLAND" desc="In the language menu button, this shows the input mode.">
Polish keyboard layout
Polish
</message>
<message name="IDS_STATUSBAR_LAYOUT_DENMARK" desc="In the language menu button, this shows the input mode.">
Danish keyboard layout
Danish
</message>
<message name="IDS_STATUSBAR_LAYOUT_CROATIA" desc="In the language menu button, this shows the input mode.">
Croatian keyboard layout
Croatian
</message>
<message name="IDS_STATUSBAR_LAYOUT_BRAZIL" desc="In the language menu button, this shows the input mode.">
Brazilian keyboard layout
Brazilian
</message>
<message name="IDS_STATUSBAR_LAYOUT_SERBIA" desc="In the language menu button, this shows the input mode.">
Serbian keyboard layout
Serbian
</message>
<message name="IDS_STATUSBAR_LAYOUT_CZECHIA" desc="In the language menu button, this shows the input mode.">
Czechian keyboard layout
Czechian
</message>
<message name="IDS_STATUSBAR_LAYOUT_USA_DVORAK" desc="In the language menu button, this shows the input mode.">
English (Dvorak) keyboard layout
English (Dvorak)
</message>
<message name="IDS_STATUSBAR_LAYOUT_ROMANIA" desc="In the language menu button, this shows the input mode.">
Romanian keyboard layout
Romanian
</message>
<message name="IDS_STATUSBAR_LAYOUT_USA" desc="In the language menu button, this shows the input mode.">
English (USA) keyboard layout
English (USA)
</message>
<message name="IDS_STATUSBAR_LAYOUT_LITHUANIA" desc="In the language menu button, this shows the input mode.">
Lithuanian keyboard layout
Lithuanian
</message>
<message name="IDS_STATUSBAR_LAYOUT_UNITED_KINGDOM" desc="In the language menu button, this shows the input mode.">
English (UK) keyboard layout
English (UK)
</message>
<message name="IDS_STATUSBAR_LAYOUT_SLOVAKIA" desc="In the language menu button, this shows the input mode.">
Slovakian keyboard layout
Slovakian
</message>
<message name="IDS_STATUSBAR_LAYOUT_RUSSIA" desc="In the language menu button, this shows the input mode.">
Russian keyboard layout
Russian
</message>
<message name="IDS_STATUSBAR_LAYOUT_GREECE" desc="In the language menu button, this shows the input mode.">
Greek keyboard layout
Greek
</message>
<message name="IDS_STATUSBAR_LAYOUT_BELGIUM" desc="In the language menu button, this shows the input mode.">
Belgian keyboard layout
......@@ -9253,43 +9253,43 @@ Keep your key file in a safe place. You will need it to create new versions of y
Swiss (French) keyboard layout
</message>
<message name="IDS_STATUSBAR_LAYOUT_TURKEY" desc="In the language menu button, this shows the input mode.">
Turkish keyboard layout
Turkish
</message>
<message name="IDS_STATUSBAR_LAYOUT_PORTUGAL" desc="In the language menu button, this shows the input mode.">
Portugese keyboard layout
Portugese
</message>
<message name="IDS_STATUSBAR_LAYOUT_SPAIN" desc="In the language menu button, this shows the input mode.">
Spanish keyboard layout
Spanish
</message>
<message name="IDS_STATUSBAR_LAYOUT_FINLAND" desc="In the language menu button, this shows the input mode.">
Finnish keyboard layout
Finnish
</message>
<message name="IDS_STATUSBAR_LAYOUT_UKRAINE" desc="In the language menu button, this shows the input mode.">
Ukrainian keyboard layout
Ukrainian
</message>
<message name="IDS_STATUSBAR_LAYOUT_SPAIN_CATALAN" desc="In the language menu button, this shows the input mode.">
Spanish (Catalan) keyboard layout
Spanish (Catalan)
</message>
<message name="IDS_STATUSBAR_LAYOUT_FRANCE" desc="In the language menu button, this shows the input mode.">
French keyboard layout
</message>
<message name="IDS_STATUSBAR_LAYOUT_NORWAY" desc="In the language menu button, this shows the input mode.">
Norwegian keyboard layout
Norwegian
</message>
<message name="IDS_STATUSBAR_LAYOUT_SWEDEN" desc="In the language menu button, this shows the input mode.">
Swedish keyboard layout
Swedish
</message>
<message name="IDS_STATUSBAR_LAYOUT_NETHERLANDS" desc="In the language menu button, this shows the input mode.">
Dutch keyboard layout
</message>
<message name="IDS_STATUSBAR_LAYOUT_LATVIA" desc="In the language menu button, this shows the input mode.">
Latvian keyboard layout
Latvian
</message>
<message name="IDS_STATUSBAR_LAYOUT_CANADA" desc="In the language menu button, this shows the input mode.">
Canadian (French) keyboard layout
</message>
<message name="IDS_STATUSBAR_LAYOUT_CANADA_ENGLISH" desc="In the language menu button, this shows the input mode.">
Canadian (English) keyboard layout
Canadian (English)
</message>
<message name="IDS_LOGIN_ERROR_AUTHENTICATING" desc="Couldn't log in because password is invalid">
......
......@@ -321,13 +321,7 @@ string16 LanguageMenuButton::GetLabelAt(int index) const {
std::wstring name;
if (IndexIsInInputMethodList(index)) {
const std::string language_code =
input_method::GetLanguageCodeFromDescriptor(
input_method_descriptors_->at(index));
const bool need_method_name =
(ambiguous_language_code_set_.count(language_code) > 0);
name = GetTextForMenu(input_method_descriptors_->at(index),
need_method_name);
name = GetTextForMenu(input_method_descriptors_->at(index));
} else if (GetPropertyIndex(index, &index)) {
const ImePropertyList& property_list
= CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties();
......@@ -493,8 +487,7 @@ void LanguageMenuButton::UpdateIndicator(
void LanguageMenuButton::UpdateIndicatorFromInputMethod(
const InputMethodDescriptor& input_method) {
const std::wstring name = GetTextForIndicator(input_method);
const std::wstring tooltip =
GetTextForMenu(input_method, true /* add_method_name */);
const std::wstring tooltip = GetTextForMenu(input_method);
UpdateIndicator(name, tooltip);
}
......@@ -504,7 +497,6 @@ void LanguageMenuButton::RebuildModel() {
// Indicates if separator's needed before each section.
bool need_separator = false;
ambiguous_language_code_set_.clear();
if (!input_method_descriptors_->empty()) {
// We "abuse" the command_id and group_id arguments of AddRadioItem method.
// A COMMAND_ID_XXX enum value is passed as command_id, and array index of
......@@ -513,8 +505,6 @@ void LanguageMenuButton::RebuildModel() {
model_->AddRadioItem(COMMAND_ID_INPUT_METHODS, dummy_label, i);
}
GetAmbiguousLanguageCodeSet(*input_method_descriptors_,
&ambiguous_language_code_set_);
need_separator = true;
}
......@@ -637,18 +627,27 @@ std::wstring LanguageMenuButton::GetTextForIndicator(
}
std::wstring LanguageMenuButton::GetTextForMenu(
const InputMethodDescriptor& input_method, bool add_method_name) {
const InputMethodDescriptor& input_method) {
// We don't show language here. Name of keyboard layout or input method
// usually imply (or explicitly include) its language.
// Special case for Dutch, French and German: these languages have multiple
// keyboard layouts and share the same laout of keyboard (Belgian). We need to
// show explicitly the language for the layout.
// For Arabic, Hebrew and Hindi: they share "Standard Input Method".
const std::string language_code
= input_method::GetLanguageCodeFromDescriptor(input_method);
// For the drop-down menu and tooltip, we'll show language names like
// "Chinese (Simplified)" and "Japanese", instead of input method names
// like "Pinyin" and "Mozc".
std::wstring text = GetLanguageName(language_code);
if (add_method_name) {
text += L" - ";
text += input_method::GetString(input_method.display_name);
std::wstring text;
if (language_code == "ar" ||
language_code == "he" ||
language_code == "hi" ||
language_code == "nl" ||
language_code == "fr" ||
language_code == "de") {
text = GetLanguageName(language_code) + L" - ";
}
text += input_method::GetString(input_method.display_name);
DCHECK(!text.empty());
return text;
}
......@@ -658,31 +657,6 @@ void LanguageMenuButton::RegisterPrefs(PrefService* local_state) {
"");
}
void LanguageMenuButton::GetAmbiguousLanguageCodeSet(
const InputMethodDescriptors& input_method_descriptors,
std::set<std::string>* ambiguous_language_code_set) {
DCHECK(ambiguous_language_code_set);
ambiguous_language_code_set->clear();
std::set<std::string> languages_seen;
for (size_t i = 0; i < input_method_descriptors.size(); ++i) {
const std::string language_code
= input_method::GetLanguageCodeFromDescriptor(
input_method_descriptors.at(i));
// If there is more than one input method for this language, then we need
// to display the method name.
if (languages_seen.count(language_code) > 0 ||
// Special-case Japanese as showing the language name alone is
// confusing when Japanese keyboard is enabled but Japanese
// input methods are not.
language_code == "ja") {
ambiguous_language_code_set->insert(language_code);
} else {
languages_seen.insert(language_code);
}
}
}
void LanguageMenuButton::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
......
......@@ -70,20 +70,11 @@ class LanguageMenuButton : public StatusAreaButton,
// Converts an InputMethodDescriptor object into human readable string.
// Returns a string for the drop-down menu and the tooltip for the indicator.
static std::wstring GetTextForMenu(
const InputMethodDescriptor& input_method, bool add_method_name);
static std::wstring GetTextForMenu(const InputMethodDescriptor& input_method);
// Registers input method preferences for the login screen.
static void RegisterPrefs(PrefService* local_state);
// Gets the language codes that are ambiguous if we only show the
// language names in the menu. For these languages, we'll show the input
// method names in addition to the language names. The original contents
// of |ambiguous_language_code_set| are lost.
static void GetAmbiguousLanguageCodeSet(
const InputMethodDescriptors& input_method_descriptors,
std::set<std::string>* ambiguous_language_code_set);
protected:
// views::View implementation.
virtual void OnLocaleChanged();
......@@ -123,10 +114,6 @@ class LanguageMenuButton : public StatusAreaButton,
StringPrefMember previous_input_method_pref_;
StringPrefMember current_input_method_pref_;
// Language codes that can be ambiguous. See comments at
// GetAmbiguousLanguageCodeSet() for details.
std::set<std::string> ambiguous_language_code_set_;
// We borrow menus::SimpleMenuModel implementation to maintain the current
// content of the pop-up menu. The menus::MenuModel is implemented using this
// |model_|.
......
......@@ -65,63 +65,97 @@ TEST(LanguageMenuButtonTest, GetTextForIndicatorTest) {
}
}
TEST(LanguageMenuButtonTest, GetTextForTooltipTest) {
const bool kAddMethodName = true;
// Test whether the function returns language name for non-ambiguous languages.
TEST(LanguageMenuButtonTest, GetTextForMenuTest) {
// For most languages input method or keyboard layout name is returned.
// See below for exceptions.
{
InputMethodDescriptor desc("m17n:fa:isiri", "isiri (m17n)", "us", "fa");
EXPECT_EQ(L"Persian - Persian input method (ISIRI 2901 layout)",
LanguageMenuButton::GetTextForMenu(desc, kAddMethodName));
EXPECT_EQ(L"Persian input method (ISIRI 2901 layout)",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("hangul", "Korean", "us", "ko");
EXPECT_EQ(L"Korean - Korean input method",
LanguageMenuButton::GetTextForMenu(desc, kAddMethodName));
EXPECT_EQ(L"Korean input method",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("m17n:vi:tcvn", "tcvn (m17n)", "us", "vi");
EXPECT_EQ(L"Vietnamese input method (TCVN6064)",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("mozc", "Mozc (US keyboard layout)", "us", "ja");
EXPECT_EQ(L"Japanese input method (for US keyboard)",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:jp::jpn", "Japan", "jp", "jpn");
EXPECT_EQ(L"Japanese keyboard layout",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:us:dvorak:eng", "USA - Dvorak",
"us(dvorak)", "eng");
EXPECT_EQ(L"English (Dvorak)",
LanguageMenuButton::GetTextForMenu(desc));
}
// For Arabic, Dutch, French, German, Hebrew and Hindi,
// "language - keyboard layout" pair is returned.
{
InputMethodDescriptor desc("m17n:ar:kbd", "kbd (m17n)", "us", "ar");
EXPECT_EQ(L"Arabic - Standard input method",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:nl::nld", "Netherlands", "nl", "nld");
EXPECT_EQ(L"Dutch - Dutch keyboard layout",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:be::nld", "Belgium", "be", "nld");
EXPECT_EQ(L"Dutch - Belgian keyboard layout",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:fr::fra", "France", "fr", "fra");
EXPECT_EQ(L"French - French keyboard layout",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:be::fra", "Belgium", "be", "fra");
EXPECT_EQ(L"French - Belgian keyboard layout",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:de::ger", "Germany", "de", "ger");
EXPECT_EQ(L"German - German keyboard layout",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("xkb:be::ger", "Belgium", "be", "ger");
EXPECT_EQ(L"German - Belgian keyboard layout",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("m17n:he:kbd", "kbd (m17n)", "us", "he");
EXPECT_EQ(L"Hebrew - Standard input method",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("m17n:hi:itrans", "itrans (m17n)", "us", "hi");
EXPECT_EQ(L"Hindi - Standard input method",
LanguageMenuButton::GetTextForMenu(desc));
}
{
InputMethodDescriptor desc("invalid-id", "unregistered string", "us", "xx");
// You can safely ignore the "Resouce ID is not found for: unregistered
// string" error.
EXPECT_EQ(L"xx - unregistered string",
LanguageMenuButton::GetTextForMenu(desc, kAddMethodName));
}
}
TEST(LanguageMenuButtonTest, GetAmbiguousLanguageCodeSet) {
{
std::set<std::string> ambiguous_language_code_set;
InputMethodDescriptors descriptors;
descriptors.push_back(InputMethodDescriptor(
"xkb:us::eng", "USA", "us", "eng"));
LanguageMenuButton::GetAmbiguousLanguageCodeSet(
descriptors, &ambiguous_language_code_set);
// There is no ambituity.
EXPECT_TRUE(ambiguous_language_code_set.empty());
}
{
std::set<std::string> ambiguous_language_code_set;
InputMethodDescriptors descriptors;
descriptors.push_back(InputMethodDescriptor(
"xkb:us::eng", "USA", "us", "eng"));
descriptors.push_back(InputMethodDescriptor(
"xkb:us:dvorak:eng", "Dvorak", "us", "eng"));
LanguageMenuButton::GetAmbiguousLanguageCodeSet(
descriptors, &ambiguous_language_code_set);
// This is ambiguous, as two input methods are present for "en-US".
EXPECT_EQ(1U, ambiguous_language_code_set.size());
EXPECT_EQ(1U, ambiguous_language_code_set.count("en-US"));
}
{
std::set<std::string> ambiguous_language_code_set;
InputMethodDescriptors descriptors;
descriptors.push_back(InputMethodDescriptor(
"xkb:jp::jpn", "Japan", "jp", "jpn"));
LanguageMenuButton::GetAmbiguousLanguageCodeSet(
descriptors, &ambiguous_language_code_set);
// Japanese is special. Showing the language name alone for the
// Japanese keyboard layout is confusing, hence we consider it
// ambiguous.
EXPECT_EQ(1U, ambiguous_language_code_set.size());
EXPECT_EQ(1U, ambiguous_language_code_set.count("ja"));
EXPECT_EQ(L"unregistered string",
LanguageMenuButton::GetTextForMenu(desc));
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment