Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/ui/webui/options2/language_options_handler2.cc

Issue 10255017: Fixed failure to add language in language settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ui/webui/options2/language_options_handler2.h" 5 #include "chrome/browser/ui/webui/options2/language_options_handler2.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 std::vector<string16> display_names; 73 std::vector<string16> display_names;
74 74
75 // Build the list of display names, and build the language map. 75 // Build the list of display names, and build the language map.
76 for (size_t i = 0; i < language_codes.size(); ++i) { 76 for (size_t i = 0; i < language_codes.size(); ++i) {
77 string16 display_name = 77 string16 display_name =
78 l10n_util::GetDisplayNameForLocale(language_codes[i], app_locale, 78 l10n_util::GetDisplayNameForLocale(language_codes[i], app_locale,
79 false); 79 false);
80 string16 native_display_name = 80 string16 native_display_name =
81 l10n_util::GetDisplayNameForLocale(language_codes[i], language_codes[i], 81 l10n_util::GetDisplayNameForLocale(language_codes[i], language_codes[i],
82 false); 82 false);
83 base::i18n::AdjustStringForLocaleDirection(&native_display_name);
84 display_names.push_back(display_name); 83 display_names.push_back(display_name);
85 language_map[display_name] = 84 language_map[display_name] =
86 std::make_pair(language_codes[i], native_display_name); 85 std::make_pair(language_codes[i], native_display_name);
87 } 86 }
88 DCHECK_EQ(display_names.size(), language_map.size()); 87 DCHECK_EQ(display_names.size(), language_map.size());
89 88
90 // Sort display names using locale specific sorter. 89 // Sort display names using locale specific sorter.
91 l10n_util::SortStrings16(app_locale, &display_names); 90 l10n_util::SortStrings16(app_locale, &display_names);
92 91
93 // Build the language list from the language map. 92 // Build the language list from the language map.
94 ListValue* language_list = new ListValue(); 93 ListValue* language_list = new ListValue();
95 for (size_t i = 0; i < display_names.size(); ++i) { 94 for (size_t i = 0; i < display_names.size(); ++i) {
96 const LanguagePair& pair = language_map[display_names[i]]; 95 string16& display_name = display_names[i];
97 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars( 96 string16 adjusted_display_name(display_name);
98 display_names[i]); 97 base::i18n::AdjustStringForLocaleDirection(&adjusted_display_name);
98
99 const LanguagePair& pair = language_map[display_name];
100 string16 adjusted_native_display_name(pair.second);
101 base::i18n::AdjustStringForLocaleDirection(&adjusted_native_display_name);
102
103 bool has_rtl_chars = base::i18n::StringContainsStrongRTLChars(display_name);
99 std::string directionality = has_rtl_chars ? "rtl" : "ltr"; 104 std::string directionality = has_rtl_chars ? "rtl" : "ltr";
105
100 DictionaryValue* dictionary = new DictionaryValue(); 106 DictionaryValue* dictionary = new DictionaryValue();
101 dictionary->SetString("code", pair.first); 107 dictionary->SetString("code", pair.first);
102 dictionary->SetString("displayName", display_names[i]); 108 dictionary->SetString("displayName", adjusted_display_name);
103 dictionary->SetString("textDirection", directionality); 109 dictionary->SetString("textDirection", directionality);
104 dictionary->SetString("nativeDisplayName", pair.second); 110 dictionary->SetString("nativeDisplayName", adjusted_native_display_name);
105 language_list->Append(dictionary); 111 language_list->Append(dictionary);
106 } 112 }
107 113
108 return language_list; 114 return language_list;
109 } 115 }
110 116
111 string16 LanguageOptionsHandler::GetProductName() { 117 string16 LanguageOptionsHandler::GetProductName() {
112 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 118 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
113 } 119 }
114 120
115 void LanguageOptionsHandler::SetApplicationLocale( 121 void LanguageOptionsHandler::SetApplicationLocale(
116 const std::string& language_code) { 122 const std::string& language_code) {
117 PrefService* pref_service = g_browser_process->local_state(); 123 PrefService* pref_service = g_browser_process->local_state();
118 pref_service->SetString(prefs::kApplicationLocale, language_code); 124 pref_service->SetString(prefs::kApplicationLocale, language_code);
119 } 125 }
120 126
121 void LanguageOptionsHandler::RestartCallback(const ListValue* args) { 127 void LanguageOptionsHandler::RestartCallback(const ListValue* args) {
122 content::RecordAction(UserMetricsAction("LanguageOptions_Restart")); 128 content::RecordAction(UserMetricsAction("LanguageOptions_Restart"));
123 BrowserList::AttemptRestart(); 129 BrowserList::AttemptRestart();
124 } 130 }
125 131
126 } // namespace options2 132 } // namespace options2
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698