OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 xkb_layout_to_indicator_[kXkbIndicators[i][0]] = kXkbIndicators[i][1]; | 395 xkb_layout_to_indicator_[kXkbIndicators[i][0]] = kXkbIndicators[i][1]; |
396 } | 396 } |
397 } | 397 } |
398 | 398 |
399 InputMethodUtil::~InputMethodUtil() { | 399 InputMethodUtil::~InputMethodUtil() { |
400 } | 400 } |
401 | 401 |
402 bool InputMethodUtil::TranslateStringInternal( | 402 bool InputMethodUtil::TranslateStringInternal( |
403 const std::string& english_string, base::string16 *out_string) const { | 403 const std::string& english_string, base::string16 *out_string) const { |
404 DCHECK(out_string); | 404 DCHECK(out_string); |
405 HashType::const_iterator iter = english_to_resource_id_.find(english_string); | 405 // |english_string| could be an input method id. So legacy xkb id is required |
| 406 // to get the translated string. |
| 407 std::string key_string = extension_ime_util::MaybeGetLegacyXkbId( |
| 408 english_string); |
| 409 HashType::const_iterator iter = english_to_resource_id_.find(key_string); |
| 410 |
406 if (iter == english_to_resource_id_.end()) { | 411 if (iter == english_to_resource_id_.end()) { |
407 // TODO(yusukes): Write Autotest which checks if all display names and all | 412 // TODO(yusukes): Write Autotest which checks if all display names and all |
408 // property names for supported input methods are listed in the resource | 413 // property names for supported input methods are listed in the resource |
409 // ID array (crosbug.com/4572). | 414 // ID array (crosbug.com/4572). |
410 LOG(ERROR) << "Resource ID is not found for: " << english_string; | 415 LOG(ERROR) << "Resource ID is not found for: " << key_string; |
411 return false; | 416 return false; |
412 } | 417 } |
413 | 418 |
414 *out_string = delegate_->GetLocalizedString(iter->second); | 419 *out_string = delegate_->GetLocalizedString(iter->second); |
415 return true; | 420 return true; |
416 } | 421 } |
417 | 422 |
418 base::string16 InputMethodUtil::TranslateString( | 423 base::string16 InputMethodUtil::TranslateString( |
419 const std::string& english_string) const { | 424 const std::string& english_string) const { |
420 base::string16 localized_string; | 425 base::string16 localized_string; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 // Special case for German, French and Dutch: these languages have multiple | 548 // Special case for German, French and Dutch: these languages have multiple |
544 // keyboard layouts and share the same layout of keyboard (Belgian). We need | 549 // keyboard layouts and share the same layout of keyboard (Belgian). We need |
545 // to show explicitly the language for the layout. For Arabic, Amharic, and | 550 // to show explicitly the language for the layout. For Arabic, Amharic, and |
546 // Indic languages: they share "Standard Input Method". | 551 // Indic languages: they share "Standard Input Method". |
547 const base::string16 standard_input_method_text = | 552 const base::string16 standard_input_method_text = |
548 delegate_->GetLocalizedString( | 553 delegate_->GetLocalizedString( |
549 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD); | 554 IDS_OPTIONS_SETTINGS_LANGUAGES_M17N_STANDARD_INPUT_METHOD); |
550 DCHECK(!input_method.language_codes().empty()); | 555 DCHECK(!input_method.language_codes().empty()); |
551 const std::string language_code = input_method.language_codes().at(0); | 556 const std::string language_code = input_method.language_codes().at(0); |
552 | 557 |
553 // Before translate the string, convert the input method id to legacy xkb id | 558 base::string16 text = TranslateString(input_method.id()); |
554 // if possible. | |
555 // TODO(shuchen): the GetInputMethodLongName() method should be removed when | |
556 // finish the wrapping of xkb to extension. | |
557 base::string16 text = TranslateString( | |
558 extension_ime_util::MaybeGetLegacyXkbId(input_method.id())); | |
559 if (text == standard_input_method_text || | 559 if (text == standard_input_method_text || |
560 language_code == "de" || | 560 language_code == "de" || |
561 language_code == "fr" || | 561 language_code == "fr" || |
562 language_code == "nl") { | 562 language_code == "nl") { |
563 const base::string16 language_name = delegate_->GetDisplayLanguageName( | 563 const base::string16 language_name = delegate_->GetDisplayLanguageName( |
564 language_code); | 564 language_code); |
565 | 565 |
566 text = language_name + base::UTF8ToUTF16(" - ") + text; | 566 text = language_name + base::UTF8ToUTF16(" - ") + text; |
567 } | 567 } |
568 | 568 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 std::make_pair(language_codes[i], input_method_id)); | 899 std::make_pair(language_codes[i], input_method_id)); |
900 // Remember the pairs. | 900 // Remember the pairs. |
901 id_to_language_code_.insert( | 901 id_to_language_code_.insert( |
902 std::make_pair(input_method_id, language_codes[i])); | 902 std::make_pair(input_method_id, language_codes[i])); |
903 } | 903 } |
904 } | 904 } |
905 } | 905 } |
906 | 906 |
907 } // namespace input_method | 907 } // namespace input_method |
908 } // namespace chromeos | 908 } // namespace chromeos |
OLD | NEW |