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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc

Issue 224093013: Allow country-specific languages in UI list at OOBE. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 6 years, 8 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
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/options/chromeos/cros_language_options_handler .h" 5 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler .h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 LanguageMap language_map; 226 LanguageMap language_map;
227 227
228 // The auxiliary vector mentioned above. (except vendor locales) 228 // The auxiliary vector mentioned above. (except vendor locales)
229 std::vector<base::string16> display_names; 229 std::vector<base::string16> display_names;
230 230
231 // Separate vector of vendor locales. 231 // Separate vector of vendor locales.
232 std::vector<base::string16> configured_locales_display_names( 232 std::vector<base::string16> configured_locales_display_names(
233 configured_locales.size()); 233 configured_locales.size());
234 234
235 size_t configured_locales_count = 0; 235 size_t configured_locales_count = 0;
236
236 // Build the list of display names, and build the language map. 237 // Build the list of display names, and build the language map.
238
239 // The list of configured locales might have entries not in
240 // base_language_codes. If there are unsipported language variants,
Nikita (slow) 2014/04/07 04:54:27 nit: unsupported
Alexander Alekseev 2014/04/07 16:56:28 Done.
241 // replace them with base language from base_language_codes if supported.
242 for (std::map<std::string, int>::const_iterator iter = language_index.begin();
Nikita (slow) 2014/04/07 04:54:27 Why this new code in chrome://settings is necessar
Alexander Alekseev 2014/04/07 16:56:28 Because the list of languages at OOBE is actually
243 iter != language_index.end();
244 ++iter) {
245 const std::string& language_id = iter->first;
246 const int language_idx = iter->second;
247
248 const size_t dash_pos = language_id.find_first_of('-');
249
250 // Ignore non-specific codes.
251 if (dash_pos == std::string::npos || dash_pos == 0)
252 continue;
253
254 if (std::find(base_language_codes.begin(),
255 base_language_codes.end(),
256 language_id) != base_language_codes.end()) {
257 // Language is supported. No need to replace
258 continue;
259 }
260 const std::string base_language_code = language_id.substr(0, dash_pos);
261 if (std::find(base_language_codes.begin(),
262 base_language_codes.end(),
263 base_language_code) == base_language_codes.end()) {
264 // Base language is not supported.
265 continue;
266 }
267
268 const base::string16 display_name =
269 l10n_util::GetDisplayNameForLocale(language_id, app_locale, true);
270 const base::string16 native_display_name =
271 l10n_util::GetDisplayNameForLocale(
272 language_id, language_id, true);
273
274 language_map[display_name] =
275 std::make_pair(language_id, native_display_name);
276
277 configured_locales_display_names[language_idx] = display_name;
278 ++configured_locales_count;
279 }
280
281 // Translate language codes, generated from input methods.
237 for (std::set<std::string>::const_iterator iter = language_codes.begin(); 282 for (std::set<std::string>::const_iterator iter = language_codes.begin();
238 iter != language_codes.end(); ++iter) { 283 iter != language_codes.end(); ++iter) {
239 // Exclude the language which is not in |base_langauge_codes| even it has 284 // Exclude the language which is not in |base_langauge_codes| even it has
240 // input methods. 285 // input methods.
241 if (std::find(base_language_codes.begin(), 286 if (std::find(base_language_codes.begin(),
242 base_language_codes.end(), 287 base_language_codes.end(),
243 *iter) == base_language_codes.end()) { 288 *iter) == base_language_codes.end()) {
244 continue; 289 continue;
245 } 290 }
246 291
247 const base::string16 display_name = 292 const base::string16 display_name =
248 l10n_util::GetDisplayNameForLocale(*iter, app_locale, true); 293 l10n_util::GetDisplayNameForLocale(*iter, app_locale, true);
249 const base::string16 native_display_name = 294 const base::string16 native_display_name =
250 l10n_util::GetDisplayNameForLocale(*iter, *iter, true); 295 l10n_util::GetDisplayNameForLocale(*iter, *iter, true);
251 296
252 language_map[display_name] = 297 language_map[display_name] =
253 std::make_pair(*iter, native_display_name); 298 std::make_pair(*iter, native_display_name);
254 299
255 const std::map<std::string, int>::const_iterator index_pos = 300 const std::map<std::string, int>::const_iterator index_pos =
256 language_index.find(*iter); 301 language_index.find(*iter);
257 if (index_pos != language_index.end()) { 302 if (index_pos != language_index.end()) {
258 configured_locales_display_names[index_pos->second] = display_name; 303 base::string16& stored_display_name =
259 ++configured_locales_count; 304 configured_locales_display_names[index_pos->second];
305 if (stored_display_name.empty()) {
306 stored_display_name = display_name;
307 ++configured_locales_count;
308 }
260 } else { 309 } else {
261 display_names.push_back(display_name); 310 display_names.push_back(display_name);
262 } 311 }
263 } 312 }
264 DCHECK_EQ(display_names.size() + configured_locales_count, 313 DCHECK_EQ(display_names.size() + configured_locales_count,
265 language_map.size()); 314 language_map.size());
266 315
267 // Build the list of display names, and build the language map. 316 // Build the list of display names, and build the language map.
268 for (size_t i = 0; i < base_language_codes.size(); ++i) { 317 for (size_t i = 0; i < base_language_codes.size(); ++i) {
269 // Skip this language if it was already added. 318 // Skip this language if it was already added.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 ConvertInputMethodDescriptosToIMEList( 541 ConvertInputMethodDescriptosToIMEList(
493 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); 542 component_extension_manager->GetAllIMEAsInputMethodDescriptor()));
494 web_ui()->CallJavascriptFunction( 543 web_ui()->CallJavascriptFunction(
495 "options.LanguageOptions.onComponentManagerInitialized", 544 "options.LanguageOptions.onComponentManagerInitialized",
496 *ime_list); 545 *ime_list);
497 composition_extension_appended_ = true; 546 composition_extension_appended_ = true;
498 } 547 }
499 548
500 } // namespace options 549 } // namespace options
501 } // namespace chromeos 550 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698