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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/l10n_util.cc

Issue 483523005: Default to current UI locale when recommended locales are invalid (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix code that was not actually working. Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/login/l10n_util.h" 5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 364
365 language_info->SetString("value", value); 365 language_info->SetString("value", value);
366 language_info->SetString("title", display_name); 366 language_info->SetString("title", display_name);
367 if (value == selected) 367 if (value == selected)
368 language_info->SetBoolean("selected", true); 368 language_info->SetBoolean("selected", true);
369 } 369 }
370 return languages_list.Pass(); 370 return languages_list.Pass();
371 } 371 }
372 372
373 std::string FindMostRelevantLocale(
374 const std::vector<std::string>& most_relevant_language_codes,
375 const base::ListValue& available_locales,
376 const std::string& fallback_locale) {
377 for (std::vector<std::string>::const_iterator most_relevant_it =
378 most_relevant_language_codes.begin();
379 most_relevant_it != most_relevant_language_codes.end();
380 ++most_relevant_it) {
381 for (base::ListValue::const_iterator available_it =
382 available_locales.begin();
383 available_it != available_locales.end(); ++available_it) {
384 base::DictionaryValue* dict;
385 std::string available_locale;
386 if (!(*available_it)->GetAsDictionary(&dict) ||
387 !dict->GetString("value", &available_locale)) {
388 NOTREACHED();
389 continue;
390 }
391 if (available_locale == *most_relevant_it)
392 return *most_relevant_it;
393 }
394 }
395
396 return fallback_locale;
397 }
398
373 scoped_ptr<base::ListValue> GetAcceptLanguageList() { 399 scoped_ptr<base::ListValue> GetAcceptLanguageList() {
374 // Collect the language codes from the supported accept-languages. 400 // Collect the language codes from the supported accept-languages.
375 const std::string app_locale = g_browser_process->GetApplicationLocale(); 401 const std::string app_locale = g_browser_process->GetApplicationLocale();
376 std::vector<std::string> accept_language_codes; 402 std::vector<std::string> accept_language_codes;
377 l10n_util::GetAcceptLanguagesForLocale(app_locale, &accept_language_codes); 403 l10n_util::GetAcceptLanguagesForLocale(app_locale, &accept_language_codes);
378 return GetLanguageList( 404 return GetLanguageList(
379 *input_method::InputMethodManager::Get()->GetSupportedInputMethods(), 405 *input_method::InputMethodManager::Get()->GetSupportedInputMethods(),
380 accept_language_codes, 406 accept_language_codes,
381 StartupCustomizationDocument::GetInstance()->configured_locales(), 407 StartupCustomizationDocument::GetInstance()->configured_locales(),
382 false); 408 false);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 worker_pool->GetNamedSequenceToken(kSequenceToken), 483 worker_pool->GetNamedSequenceToken(kSequenceToken),
458 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 484 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
459 485
460 // Resolve |locale| on a background thread, then continue on the current 486 // Resolve |locale| on a background thread, then continue on the current
461 // thread. 487 // thread.
462 std::string (*get_application_locale)(const std::string&, bool) = 488 std::string (*get_application_locale)(const std::string&, bool) =
463 &l10n_util::GetApplicationLocale; 489 &l10n_util::GetApplicationLocale;
464 base::PostTaskAndReplyWithResult( 490 base::PostTaskAndReplyWithResult(
465 background_task_runner, 491 background_task_runner,
466 FROM_HERE, 492 FROM_HERE,
467 base::Bind(get_application_locale, locale, false /* set_icu_locale*/ ), 493 base::Bind(get_application_locale, locale, false /* set_icu_locale */),
468 base::Bind(&GetKeyboardLayoutsForResolvedLocale, callback)); 494 base::Bind(&GetKeyboardLayoutsForResolvedLocale, callback));
469 } 495 }
470 496
471 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { 497 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() {
472 const input_method::InputMethodDescriptor current_input_method = 498 const input_method::InputMethodDescriptor current_input_method =
473 input_method::InputMethodManager::Get() 499 input_method::InputMethodManager::Get()
474 ->GetActiveIMEState() 500 ->GetActiveIMEState()
475 ->GetCurrentInputMethod(); 501 ->GetCurrentInputMethod();
476 return CreateInputMethodsEntry(current_input_method, 502 return CreateInputMethodsEntry(current_input_method,
477 current_input_method.id()); 503 current_input_method.id());
478 } 504 }
479 505
480 } // namespace chromeos 506 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698