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/utf_string_conversions.h" |
8 #include "base/values.h" | 9 #include "base/values.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "chrome/browser/chromeos/cros/input_method_library.h" | 12 #include "chrome/browser/chromeos/cros/input_method_library.h" |
12 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 13 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 14 #include "chrome/browser/pref_service.h" |
| 15 #include "chrome/common/pref_names.h" |
13 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
14 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
15 | 18 |
16 LanguageOptionsHandler::LanguageOptionsHandler() { | 19 LanguageOptionsHandler::LanguageOptionsHandler() { |
17 } | 20 } |
18 | 21 |
19 LanguageOptionsHandler::~LanguageOptionsHandler() { | 22 LanguageOptionsHandler::~LanguageOptionsHandler() { |
20 } | 23 } |
21 | 24 |
22 void LanguageOptionsHandler::GetLocalizedValues( | 25 void LanguageOptionsHandler::GetLocalizedValues( |
(...skipping 14 matching lines...) Expand all Loading... |
37 localized_strings->SetString(L"others", | 40 localized_strings->SetString(L"others", |
38 l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS)); | 41 l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS)); |
39 localized_strings->SetString(L"is_displayed_in_this_language", | 42 localized_strings->SetString(L"is_displayed_in_this_language", |
40 l10n_util::GetStringF( | 43 l10n_util::GetStringF( |
41 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, | 44 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, |
42 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); | 45 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); |
43 localized_strings->SetString(L"display_in_this_language", | 46 localized_strings->SetString(L"display_in_this_language", |
44 l10n_util::GetStringF( | 47 l10n_util::GetStringF( |
45 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, | 48 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, |
46 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); | 49 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); |
| 50 localized_strings->SetString(L"restart_required", |
| 51 l10n_util::GetString(IDS_OPTIONS_RESTART_REQUIRED)); |
47 | 52 |
| 53 // The followigns are resources, rather than local strings. |
| 54 localized_strings->SetString(L"currentUiLanguageCode", |
| 55 UTF8ToWide(g_browser_process->GetApplicationLocale())); |
48 localized_strings->Set(L"inputMethodList", GetInputMethodList()); | 56 localized_strings->Set(L"inputMethodList", GetInputMethodList()); |
49 localized_strings->Set(L"languageList", GetLanguageList()); | 57 localized_strings->Set(L"languageList", GetLanguageList()); |
50 } | 58 } |
51 | 59 |
| 60 void LanguageOptionsHandler::RegisterMessages() { |
| 61 DCHECK(dom_ui_); |
| 62 dom_ui_->RegisterMessageCallback("uiLanguageChange", |
| 63 NewCallback(this, |
| 64 &LanguageOptionsHandler::UiLanguageChangeCallback)); |
| 65 } |
| 66 |
52 ListValue* LanguageOptionsHandler::GetInputMethodList() { | 67 ListValue* LanguageOptionsHandler::GetInputMethodList() { |
53 using chromeos::CrosLibrary; | 68 using chromeos::CrosLibrary; |
54 | 69 |
55 ListValue* input_method_list = new ListValue(); | 70 ListValue* input_method_list = new ListValue(); |
56 | 71 |
57 // GetSupportedLanguages() never return NULL. | 72 // GetSupportedLanguages() never return NULL. |
58 scoped_ptr<chromeos::InputMethodDescriptors> descriptors( | 73 scoped_ptr<chromeos::InputMethodDescriptors> descriptors( |
59 CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); | 74 CrosLibrary::Get()->GetInputMethodLibrary()->GetSupportedInputMethods()); |
60 for (size_t i = 0; i < descriptors->size(); ++i) { | 75 for (size_t i = 0; i < descriptors->size(); ++i) { |
61 const chromeos::InputMethodDescriptor& descriptor = descriptors->at(i); | 76 const chromeos::InputMethodDescriptor& descriptor = descriptors->at(i); |
(...skipping 19 matching lines...) Expand all Loading... |
81 for (size_t i = 0; i < locales.size(); ++i) { | 96 for (size_t i = 0; i < locales.size(); ++i) { |
82 DictionaryValue* dictionary = new DictionaryValue(); | 97 DictionaryValue* dictionary = new DictionaryValue(); |
83 dictionary->SetString(L"code", UTF8ToWide(locales[i])); | 98 dictionary->SetString(L"code", UTF8ToWide(locales[i])); |
84 dictionary->SetString(L"displayName", | 99 dictionary->SetString(L"displayName", |
85 chromeos::input_method::GetLanguageDisplayNameFromCode(locales[i])); | 100 chromeos::input_method::GetLanguageDisplayNameFromCode(locales[i])); |
86 language_list->Append(dictionary); | 101 language_list->Append(dictionary); |
87 } | 102 } |
88 | 103 |
89 return language_list; | 104 return language_list; |
90 } | 105 } |
| 106 |
| 107 void LanguageOptionsHandler::UiLanguageChangeCallback( |
| 108 const Value* value) { |
| 109 if (!value || !value->IsType(Value::TYPE_LIST)) { |
| 110 NOTREACHED(); |
| 111 LOG(INFO) << "NOTREACHED"; |
| 112 return; |
| 113 } |
| 114 const ListValue* list_value = static_cast<const ListValue*>(value); |
| 115 std::string language_code; |
| 116 if (list_value->GetSize() != 1 || |
| 117 !list_value->GetString(0, &language_code)) { |
| 118 NOTREACHED(); |
| 119 LOG(INFO) << "NOTREACHED"; |
| 120 return; |
| 121 } |
| 122 PrefService* prefs = g_browser_process->local_state(); |
| 123 prefs->SetString(prefs::kApplicationLocale, language_code); |
| 124 prefs->SavePersistentPrefs(); |
| 125 dom_ui_->CallJavascriptFunction( |
| 126 L"options.LanguageOptions.uiLanguageSaved"); |
| 127 } |
OLD | NEW |