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

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: Support en-AU locale. 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 unsupported language variants,
241 // but they resolve to backup locale within base_language_codes, also
242 // add them to the list.
243 for (std::map<std::string, int>::const_iterator iter = language_index.begin();
244 iter != language_index.end();
245 ++iter) {
246 const std::string& language_id = iter->first;
247 const int language_idx = iter->second;
248
249 const size_t dash_pos = language_id.find_first_of('-');
250
251 // Ignore non-specific codes.
252 if (dash_pos == std::string::npos || dash_pos == 0)
253 continue;
254
255 if (std::find(base_language_codes.begin(),
256 base_language_codes.end(),
257 language_id) != base_language_codes.end()) {
258 // Language is supported. No need to replace
259 continue;
260 }
261 std::string resolved_locale;
262 if (!l10n_util::CheckAndResolveLocale(language_id, &resolved_locale))
263 continue;
264
265 if (std::find(base_language_codes.begin(),
266 base_language_codes.end(),
267 resolved_locale) == base_language_codes.end()) {
268 // Resolved locale is not supported.
269 continue;
270 }
271
272 const base::string16 display_name =
273 l10n_util::GetDisplayNameForLocale(language_id, app_locale, true);
274 const base::string16 native_display_name =
275 l10n_util::GetDisplayNameForLocale(
276 language_id, language_id, true);
277
278 language_map[display_name] =
279 std::make_pair(language_id, native_display_name);
280
281 configured_locales_display_names[language_idx] = display_name;
282 ++configured_locales_count;
283 }
284
285 // Translate language codes, generated from input methods.
237 for (std::set<std::string>::const_iterator iter = language_codes.begin(); 286 for (std::set<std::string>::const_iterator iter = language_codes.begin();
238 iter != language_codes.end(); ++iter) { 287 iter != language_codes.end(); ++iter) {
239 // Exclude the language which is not in |base_langauge_codes| even it has 288 // Exclude the language which is not in |base_langauge_codes| even it has
240 // input methods. 289 // input methods.
241 if (std::find(base_language_codes.begin(), 290 if (std::find(base_language_codes.begin(),
242 base_language_codes.end(), 291 base_language_codes.end(),
243 *iter) == base_language_codes.end()) { 292 *iter) == base_language_codes.end()) {
244 continue; 293 continue;
245 } 294 }
246 295
247 const base::string16 display_name = 296 const base::string16 display_name =
248 l10n_util::GetDisplayNameForLocale(*iter, app_locale, true); 297 l10n_util::GetDisplayNameForLocale(*iter, app_locale, true);
249 const base::string16 native_display_name = 298 const base::string16 native_display_name =
250 l10n_util::GetDisplayNameForLocale(*iter, *iter, true); 299 l10n_util::GetDisplayNameForLocale(*iter, *iter, true);
251 300
252 language_map[display_name] = 301 language_map[display_name] =
253 std::make_pair(*iter, native_display_name); 302 std::make_pair(*iter, native_display_name);
254 303
255 const std::map<std::string, int>::const_iterator index_pos = 304 const std::map<std::string, int>::const_iterator index_pos =
256 language_index.find(*iter); 305 language_index.find(*iter);
257 if (index_pos != language_index.end()) { 306 if (index_pos != language_index.end()) {
258 configured_locales_display_names[index_pos->second] = display_name; 307 base::string16& stored_display_name =
259 ++configured_locales_count; 308 configured_locales_display_names[index_pos->second];
309 if (stored_display_name.empty()) {
310 stored_display_name = display_name;
311 ++configured_locales_count;
312 }
260 } else { 313 } else {
261 display_names.push_back(display_name); 314 display_names.push_back(display_name);
262 } 315 }
263 } 316 }
264 DCHECK_EQ(display_names.size() + configured_locales_count, 317 DCHECK_EQ(display_names.size() + configured_locales_count,
265 language_map.size()); 318 language_map.size());
266 319
267 // Build the list of display names, and build the language map. 320 // Build the list of display names, and build the language map.
268 for (size_t i = 0; i < base_language_codes.size(); ++i) { 321 for (size_t i = 0; i < base_language_codes.size(); ++i) {
269 // Skip this language if it was already added. 322 // Skip this language if it was already added.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 ConvertInputMethodDescriptosToIMEList( 545 ConvertInputMethodDescriptosToIMEList(
493 component_extension_manager->GetAllIMEAsInputMethodDescriptor())); 546 component_extension_manager->GetAllIMEAsInputMethodDescriptor()));
494 web_ui()->CallJavascriptFunction( 547 web_ui()->CallJavascriptFunction(
495 "options.LanguageOptions.onComponentManagerInitialized", 548 "options.LanguageOptions.onComponentManagerInitialized",
496 *ime_list); 549 *ime_list);
497 composition_extension_appended_ = true; 550 composition_extension_appended_ = true;
498 } 551 }
499 552
500 } // namespace options 553 } // namespace options
501 } // namespace chromeos 554 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698