| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/options/language_options_handler_common.h" | |
| 6 | |
| 7 #include <map> | |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/bind.h" | |
| 14 #include "base/command_line.h" | |
| 15 #include "base/stringprintf.h" | |
| 16 #include "base/utf_string_conversions.h" | |
| 17 #include "base/values.h" | |
| 18 #include "chrome/browser/browser_process.h" | |
| 19 #include "chrome/browser/prefs/pref_service.h" | |
| 20 #include "chrome/browser/ui/browser_list.h" | |
| 21 #include "chrome/common/chrome_switches.h" | |
| 22 #include "chrome/common/pref_names.h" | |
| 23 #include "chrome/common/spellcheck_common.h" | |
| 24 #include "content/public/browser/user_metrics.h" | |
| 25 #include "content/public/browser/web_ui.h" | |
| 26 #include "grit/chromium_strings.h" | |
| 27 #include "grit/generated_resources.h" | |
| 28 #include "ui/base/l10n/l10n_util.h" | |
| 29 | |
| 30 using content::UserMetricsAction; | |
| 31 | |
| 32 LanguageOptionsHandlerCommon::LanguageOptionsHandlerCommon() { | |
| 33 } | |
| 34 | |
| 35 LanguageOptionsHandlerCommon::~LanguageOptionsHandlerCommon() { | |
| 36 } | |
| 37 | |
| 38 void LanguageOptionsHandlerCommon::GetLocalizedValues( | |
| 39 DictionaryValue* localized_strings) { | |
| 40 DCHECK(localized_strings); | |
| 41 string16 product_name = GetProductName(); | |
| 42 localized_strings->SetString("add_button", | |
| 43 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_BUTTON)); | |
| 44 localized_strings->SetString("languages", | |
| 45 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_LANGUAGES)); | |
| 46 localized_strings->SetString("please_add_another_language", | |
| 47 l10n_util::GetStringUTF16( | |
| 48 IDS_OPTIONS_SETTINGS_LANGUAGES_PLEASE_ADD_ANOTHER_LANGUAGE)); | |
| 49 localized_strings->SetString("remove_button", | |
| 50 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_LANGUAGES_REMOVE_BUTTON)); | |
| 51 localized_strings->SetString("add_language_instructions", | |
| 52 l10n_util::GetStringUTF16( | |
| 53 IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_INSTRUCTIONS)); | |
| 54 localized_strings->SetString("cannot_be_displayed_in_this_language", | |
| 55 l10n_util::GetStringFUTF16( | |
| 56 IDS_OPTIONS_SETTINGS_LANGUAGES_CANNOT_BE_DISPLAYED_IN_THIS_LANGUAGE, | |
| 57 product_name)); | |
| 58 localized_strings->SetString("is_displayed_in_this_language", | |
| 59 l10n_util::GetStringFUTF16( | |
| 60 IDS_OPTIONS_SETTINGS_LANGUAGES_IS_DISPLAYED_IN_THIS_LANGUAGE, | |
| 61 product_name)); | |
| 62 localized_strings->SetString("display_in_this_language", | |
| 63 l10n_util::GetStringFUTF16( | |
| 64 IDS_OPTIONS_SETTINGS_LANGUAGES_DISPLAY_IN_THIS_LANGUAGE, | |
| 65 product_name)); | |
| 66 localized_strings->SetString("this_language_is_currently_in_use", | |
| 67 l10n_util::GetStringFUTF16( | |
| 68 IDS_OPTIONS_SETTINGS_LANGUAGES_THIS_LANGUAGE_IS_CURRENTLY_IN_USE, | |
| 69 product_name)); | |
| 70 localized_strings->SetString("restart_required", | |
| 71 l10n_util::GetStringUTF16(IDS_OPTIONS_RELAUNCH_REQUIRED)); | |
| 72 // OS X uses the OS native spellchecker so no need for these strings. | |
| 73 #if !defined(OS_MACOSX) | |
| 74 localized_strings->SetString("use_this_for_spell_checking", | |
| 75 l10n_util::GetStringUTF16( | |
| 76 IDS_OPTIONS_SETTINGS_USE_THIS_FOR_SPELL_CHECKING)); | |
| 77 localized_strings->SetString("cannot_be_used_for_spell_checking", | |
| 78 l10n_util::GetStringUTF16( | |
| 79 IDS_OPTIONS_SETTINGS_CANNOT_BE_USED_FOR_SPELL_CHECKING)); | |
| 80 localized_strings->SetString("is_used_for_spell_checking", | |
| 81 l10n_util::GetStringUTF16( | |
| 82 IDS_OPTIONS_SETTINGS_IS_USED_FOR_SPELL_CHECKING)); | |
| 83 localized_strings->SetString("enable_spell_check", | |
| 84 l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_SPELLCHECK)); | |
| 85 localized_strings->SetString("enable_auto_spell_correction", | |
| 86 l10n_util::GetStringUTF16(IDS_OPTIONS_ENABLE_AUTO_SPELL_CORRECTION)); | |
| 87 #endif // !OS_MACOSX | |
| 88 localized_strings->SetString("add_language_title", | |
| 89 l10n_util::GetStringUTF16(IDS_OPTIONS_LANGUAGES_ADD_TITLE)); | |
| 90 localized_strings->SetString("add_language_select_label", | |
| 91 l10n_util::GetStringUTF16(IDS_OPTIONS_LANGUAGES_ADD_SELECT_LABEL)); | |
| 92 localized_strings->SetString("restart_button", | |
| 93 l10n_util::GetStringUTF16( | |
| 94 IDS_OPTIONS_SETTINGS_LANGUAGES_RELAUNCH_BUTTON)); | |
| 95 | |
| 96 // The following are resources, rather than local strings. | |
| 97 localized_strings->SetString("currentUiLanguageCode", | |
| 98 g_browser_process->GetApplicationLocale()); | |
| 99 localized_strings->Set("spellCheckLanguageCodeSet", | |
| 100 GetSpellCheckLanguageCodeSet()); | |
| 101 localized_strings->Set("uiLanguageCodeSet", GetUILanguageCodeSet()); | |
| 102 | |
| 103 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 104 bool experimental_spell_check_features = | |
| 105 command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures); | |
| 106 localized_strings->SetBoolean("experimentalSpellCheckFeatures", | |
| 107 experimental_spell_check_features); | |
| 108 } | |
| 109 | |
| 110 void LanguageOptionsHandlerCommon::RegisterMessages() { | |
| 111 web_ui()->RegisterMessageCallback("languageOptionsOpen", | |
| 112 base::Bind( | |
| 113 &LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback, | |
| 114 base::Unretained(this))); | |
| 115 web_ui()->RegisterMessageCallback("spellCheckLanguageChange", | |
| 116 base::Bind( | |
| 117 &LanguageOptionsHandlerCommon::SpellCheckLanguageChangeCallback, | |
| 118 base::Unretained(this))); | |
| 119 web_ui()->RegisterMessageCallback("uiLanguageChange", | |
| 120 base::Bind( | |
| 121 &LanguageOptionsHandlerCommon::UiLanguageChangeCallback, | |
| 122 base::Unretained(this))); | |
| 123 } | |
| 124 | |
| 125 DictionaryValue* LanguageOptionsHandlerCommon::GetUILanguageCodeSet() { | |
| 126 DictionaryValue* dictionary = new DictionaryValue(); | |
| 127 const std::vector<std::string>& available_locales = | |
| 128 l10n_util::GetAvailableLocales(); | |
| 129 for (size_t i = 0; i < available_locales.size(); ++i) { | |
| 130 dictionary->SetBoolean(available_locales[i], true); | |
| 131 } | |
| 132 return dictionary; | |
| 133 } | |
| 134 | |
| 135 DictionaryValue* LanguageOptionsHandlerCommon::GetSpellCheckLanguageCodeSet() { | |
| 136 DictionaryValue* dictionary = new DictionaryValue(); | |
| 137 std::vector<std::string> spell_check_languages; | |
| 138 SpellCheckCommon::SpellCheckLanguages(&spell_check_languages); | |
| 139 for (size_t i = 0; i < spell_check_languages.size(); ++i) { | |
| 140 dictionary->SetBoolean(spell_check_languages[i], true); | |
| 141 } | |
| 142 return dictionary; | |
| 143 } | |
| 144 | |
| 145 void LanguageOptionsHandlerCommon::LanguageOptionsOpenCallback( | |
| 146 const ListValue* args) { | |
| 147 content::RecordAction(UserMetricsAction("LanguageOptions_Open")); | |
| 148 } | |
| 149 | |
| 150 void LanguageOptionsHandlerCommon::UiLanguageChangeCallback( | |
| 151 const ListValue* args) { | |
| 152 const std::string language_code = UTF16ToASCII(ExtractStringValue(args)); | |
| 153 CHECK(!language_code.empty()); | |
| 154 const std::string action = base::StringPrintf( | |
| 155 "LanguageOptions_UiLanguageChange_%s", language_code.c_str()); | |
| 156 content::RecordComputedAction(action); | |
| 157 SetApplicationLocale(language_code); | |
| 158 web_ui()->CallJavascriptFunction("options.LanguageOptions.uiLanguageSaved"); | |
| 159 } | |
| 160 | |
| 161 void LanguageOptionsHandlerCommon::SpellCheckLanguageChangeCallback( | |
| 162 const ListValue* args) { | |
| 163 const std::string language_code = UTF16ToASCII(ExtractStringValue(args)); | |
| 164 CHECK(!language_code.empty()); | |
| 165 const std::string action = base::StringPrintf( | |
| 166 "LanguageOptions_SpellCheckLanguageChange_%s", language_code.c_str()); | |
| 167 content::RecordComputedAction(action); | |
| 168 } | |
| OLD | NEW |