• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/chromeos/language_chewing_handler.h"
6 
7 #include <limits>
8 
9 #include "base/logging.h"
10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "chrome/browser/chromeos/language_preferences.h"
14 #include "chrome/browser/ui/webui/options/chromeos/language_options_util.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17 
18 namespace {
19 const char kI18nPrefix[] = "Chewing_";
20 }  // namespace
21 
22 namespace chromeos {
23 
LanguageChewingHandler()24 LanguageChewingHandler::LanguageChewingHandler() {
25 }
26 
~LanguageChewingHandler()27 LanguageChewingHandler::~LanguageChewingHandler() {
28 }
29 
GetLocalizedValues(DictionaryValue * localized_strings)30 void LanguageChewingHandler::GetLocalizedValues(
31     DictionaryValue* localized_strings) {
32   DCHECK(localized_strings);
33 
34   RegisterTitle(localized_strings, "languageChewingPage",
35                 IDS_OPTIONS_SETTINGS_LANGUAGES_CHEWING_SETTINGS_TITLE);
36 
37   for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
38     localized_strings->SetString(
39         GetI18nContentValue(language_prefs::kChewingBooleanPrefs[i],
40                             kI18nPrefix),
41         l10n_util::GetStringUTF16(
42             language_prefs::kChewingBooleanPrefs[i].message_id));
43   }
44 
45   // For maximum Chinese characters in pre-edit buffer, we use slider UI.
46   {
47     const language_prefs::LanguageIntegerRangePreference& preference =
48         language_prefs::kChewingIntegerPrefs[
49             language_prefs::kChewingMaxChiSymbolLenIndex];
50     localized_strings->SetString(
51         GetI18nContentValue(preference, kI18nPrefix),
52         l10n_util::GetStringUTF16(preference.message_id));
53     localized_strings->SetString(
54         GetTemplateDataMinName(preference, kI18nPrefix),
55         base::IntToString(preference.min_pref_value));
56     localized_strings->SetString(
57         GetTemplateDataMaxName(preference, kI18nPrefix),
58         base::IntToString(preference.max_pref_value));
59   }
60 
61   // For number of candidates per page, we use select-option UI.
62   {
63     const language_prefs::LanguageIntegerRangePreference& preference =
64         language_prefs::kChewingIntegerPrefs[
65             language_prefs::kChewingCandPerPageIndex];
66     localized_strings->SetString(
67         GetI18nContentValue(preference, kI18nPrefix),
68         l10n_util::GetStringUTF16(preference.message_id));
69     ListValue* list_value = new ListValue();
70     for (int i = preference.min_pref_value; i <= preference.max_pref_value;
71          ++i) {
72       ListValue* option = new ListValue();
73       option->Append(CreateValue(i));
74       option->Append(CreateValue(i));
75       list_value->Append(option);
76     }
77     localized_strings->Set(GetTemplateDataPropertyName(preference, kI18nPrefix),
78                            list_value);
79   }
80 
81   for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs;
82        ++i) {
83     const language_prefs::LanguageMultipleChoicePreference<const char*>&
84         preference = language_prefs::kChewingMultipleChoicePrefs[i];
85     localized_strings->SetString(
86         GetI18nContentValue(preference, kI18nPrefix),
87         l10n_util::GetStringUTF16(preference.label_message_id));
88     localized_strings->Set(
89         GetTemplateDataPropertyName(preference, kI18nPrefix),
90         CreateMultipleChoiceList(preference));
91   }
92 
93   localized_strings->SetString(
94       GetI18nContentValue(language_prefs::kChewingHsuSelKeyType, kI18nPrefix),
95       l10n_util::GetStringUTF16(
96           language_prefs::kChewingHsuSelKeyType.label_message_id));
97   localized_strings->Set(
98       GetTemplateDataPropertyName(language_prefs::kChewingHsuSelKeyType,
99                                   kI18nPrefix),
100       CreateMultipleChoiceList(language_prefs::kChewingHsuSelKeyType));
101 }
102 
103 }  // namespace chromeos
104