OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/language_options_handler.h" | 5 #include "chrome/browser/chromeos/dom_ui/language_options_handler.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS)); | 38 l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS)); |
39 localized_strings->SetString(L"is_displayed_in_this_language", | 39 localized_strings->SetString(L"is_displayed_in_this_language", |
40 l10n_util::GetStringF( | 40 l10n_util::GetStringF( |
41 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, | 41 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, |
42 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); | 42 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); |
43 localized_strings->SetString(L"display_in_this_language", | 43 localized_strings->SetString(L"display_in_this_language", |
44 l10n_util::GetStringF( | 44 l10n_util::GetStringF( |
45 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, | 45 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, |
46 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); | 46 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); |
47 | 47 |
48 // Build mappings of locale code (language code) to display name | |
49 // (ex. "en-US" => "English (United States)". | |
50 const std::vector<std::string>& locales = l10n_util::GetAvailableLocales(); | |
51 for (size_t i = 0; i < locales.size(); ++i) { | |
52 localized_strings->SetString(UTF8ToWide(locales[i]), | |
53 chromeos::input_method::GetLanguageDisplayNameFromCode(locales[i])); | |
54 } | |
55 | |
56 localized_strings->Set(L"inputMethodList", GetInputMethodList()); | 48 localized_strings->Set(L"inputMethodList", GetInputMethodList()); |
| 49 localized_strings->Set(L"languageList", GetLanguageList()); |
57 } | 50 } |
58 | 51 |
59 ListValue* LanguageOptionsHandler::GetInputMethodList() { | 52 ListValue* LanguageOptionsHandler::GetInputMethodList() { |
60 using chromeos::CrosLibrary; | 53 using chromeos::CrosLibrary; |
61 | 54 |
62 ListValue* input_method_list = new ListValue(); | 55 ListValue* input_method_list = new ListValue(); |
63 | 56 |
64 // GetSupportedLanguages() never return NULL. | 57 // GetSupportedLanguages() never return NULL. |
65 scoped_ptr<chromeos::InputMethodDescriptors> descriptors( | 58 scoped_ptr<chromeos::InputMethodDescriptors> descriptors( |
66 CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); | 59 CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); |
67 for (size_t i = 0; i < descriptors->size(); ++i) { | 60 for (size_t i = 0; i < descriptors->size(); ++i) { |
68 const chromeos::InputMethodDescriptor& descriptor = descriptors->at(i); | 61 const chromeos::InputMethodDescriptor& descriptor = descriptors->at(i); |
69 const std::string language_code = | 62 const std::string language_code = |
70 chromeos::input_method::GetLanguageCodeFromDescriptor(descriptor); | 63 chromeos::input_method::GetLanguageCodeFromDescriptor(descriptor); |
71 const std::string display_name = | 64 const std::string display_name = |
72 chromeos::input_method::GetInputMethodDisplayNameFromId(descriptor.id); | 65 chromeos::input_method::GetInputMethodDisplayNameFromId(descriptor.id); |
73 | 66 |
74 DictionaryValue* dictionary = new DictionaryValue(); | 67 DictionaryValue* dictionary = new DictionaryValue(); |
75 dictionary->SetString(L"id", UTF8ToWide(descriptor.id)); | 68 dictionary->SetString(L"id", UTF8ToWide(descriptor.id)); |
76 dictionary->SetString(L"displayName", UTF8ToWide(display_name)); | 69 dictionary->SetString(L"displayName", UTF8ToWide(display_name)); |
77 dictionary->SetString(L"languageCode", UTF8ToWide(language_code)); | 70 dictionary->SetString(L"languageCode", UTF8ToWide(language_code)); |
78 input_method_list->Append(dictionary); | 71 input_method_list->Append(dictionary); |
79 } | 72 } |
80 | 73 |
81 return input_method_list; | 74 return input_method_list; |
82 } | 75 } |
| 76 |
| 77 ListValue* LanguageOptionsHandler::GetLanguageList() { |
| 78 ListValue* language_list = new ListValue(); |
| 79 |
| 80 const std::vector<std::string>& locales = l10n_util::GetAvailableLocales(); |
| 81 for (size_t i = 0; i < locales.size(); ++i) { |
| 82 DictionaryValue* dictionary = new DictionaryValue(); |
| 83 dictionary->SetString(L"code", UTF8ToWide(locales[i])); |
| 84 dictionary->SetString(L"displayName", |
| 85 chromeos::input_method::GetLanguageDisplayNameFromCode(locales[i])); |
| 86 language_list->Append(dictionary); |
| 87 } |
| 88 |
| 89 return language_list; |
| 90 } |
OLD | NEW |