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

Side by Side Diff: ui/base/l10n/l10n_util.cc

Issue 486203002: Do not switch the ICU locale when interacting with public session pods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. 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 (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 "ui/base/l10n/l10n_util.h" 5 #include "ui/base/l10n/l10n_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdlib> 8 #include <cstdlib>
9 #include <iterator> 9 #include <iterator>
10 #include <string> 10 #include <string>
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 resolved_locale->swap(tmp_locale); 394 resolved_locale->swap(tmp_locale);
395 return true; 395 return true;
396 } 396 }
397 } 397 }
398 } 398 }
399 399
400 return false; 400 return false;
401 #endif 401 #endif
402 } 402 }
403 403
404 std::string GetApplicationLocale(const std::string& pref_locale) { 404 std::string GetApplicationLocaleInternal(const std::string& pref_locale) {
405 #if defined(OS_MACOSX) 405 #if defined(OS_MACOSX)
406 406
407 // Use any override (Cocoa for the browser), otherwise use the preference 407 // Use any override (Cocoa for the browser), otherwise use the preference
408 // passed to the function. 408 // passed to the function.
409 std::string app_locale = l10n_util::GetLocaleOverride(); 409 std::string app_locale = l10n_util::GetLocaleOverride();
410 if (app_locale.empty()) 410 if (app_locale.empty())
411 app_locale = pref_locale; 411 app_locale = pref_locale;
412 412
413 // The above should handle all of the cases Chrome normally hits, but for some 413 // The above should handle all of the cases Chrome normally hits, but for some
414 // unit tests, we need something to fall back too. 414 // unit tests, we need something to fall back too.
415 if (app_locale.empty()) 415 if (app_locale.empty())
416 app_locale = "en-US"; 416 app_locale = "en-US";
417 417
418 // Windows/Linux call SetICUDefaultLocale after determining the actual locale
419 // with CheckAndResolveLocal to make ICU APIs work in that locale.
420 // Mac doesn't use a locale directory tree of resources (it uses Mac style
421 // resources), so mirror the Windows/Linux behavior of calling
422 // SetICUDefaultLocale.
423 base::i18n::SetICUDefaultLocale(app_locale);
424 return app_locale; 418 return app_locale;
425 419
426 #else 420 #else
427 421
428 std::string resolved_locale; 422 std::string resolved_locale;
429 std::vector<std::string> candidates; 423 std::vector<std::string> candidates;
430 424
431 // We only use --lang and the app pref on Windows. On Linux, we only 425 // We only use --lang and the app pref on Windows. On Linux, we only
432 // look at the LC_*/LANG environment variables. We do, however, pass --lang 426 // look at the LC_*/LANG environment variables. We do, however, pass --lang
433 // to renderer and plugin processes so they know what language the parent 427 // to renderer and plugin processes so they know what language the parent
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 // By default, use the application locale preference. This applies to ChromeOS 469 // By default, use the application locale preference. This applies to ChromeOS
476 // and linux systems without glib. 470 // and linux systems without glib.
477 if (!pref_locale.empty()) 471 if (!pref_locale.empty())
478 candidates.push_back(pref_locale); 472 candidates.push_back(pref_locale);
479 473
480 #endif 474 #endif
481 475
482 std::vector<std::string>::const_iterator i = candidates.begin(); 476 std::vector<std::string>::const_iterator i = candidates.begin();
483 for (; i != candidates.end(); ++i) { 477 for (; i != candidates.end(); ++i) {
484 if (CheckAndResolveLocale(*i, &resolved_locale)) { 478 if (CheckAndResolveLocale(*i, &resolved_locale)) {
485 base::i18n::SetICUDefaultLocale(resolved_locale);
486 return resolved_locale; 479 return resolved_locale;
487 } 480 }
488 } 481 }
489 482
490 // Fallback on en-US. 483 // Fallback on en-US.
491 const std::string fallback_locale("en-US"); 484 const std::string fallback_locale("en-US");
492 if (IsLocaleAvailable(fallback_locale)) { 485 if (IsLocaleAvailable(fallback_locale)) {
493 base::i18n::SetICUDefaultLocale(fallback_locale);
494 return fallback_locale; 486 return fallback_locale;
495 } 487 }
496 488
497 return std::string(); 489 return std::string();
498 490
499 #endif 491 #endif
500 } 492 }
501 493
494 std::string GetApplicationLocale(const std::string& pref_locale,
495 bool set_icu_locale) {
496 const std::string locale = GetApplicationLocaleInternal(pref_locale);
497 if (set_icu_locale && !locale.empty())
498 base::i18n::SetICUDefaultLocale(locale);
499 return locale;
500 }
501
502 std::string GetApplicationLocale(const std::string& pref_locale) {
503 return GetApplicationLocale(pref_locale, true /* set_icu_locale */);
504 }
505
502 bool IsLocaleNameTranslated(const char* locale, 506 bool IsLocaleNameTranslated(const char* locale,
503 const std::string& display_locale) { 507 const std::string& display_locale) {
504 base::string16 display_name = 508 base::string16 display_name =
505 l10n_util::GetDisplayNameForLocale(locale, display_locale, false); 509 l10n_util::GetDisplayNameForLocale(locale, display_locale, false);
506 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not 510 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not
507 // uloc_getDisplayName returns the actual translation or the default 511 // uloc_getDisplayName returns the actual translation or the default
508 // value (locale code), we have to rely on this hack to tell whether 512 // value (locale code), we have to rely on this hack to tell whether
509 // the translation is available or not. If ICU doesn't have a translated 513 // the translation is available or not. If ICU doesn't have a translated
510 // name for this locale, GetDisplayNameForLocale will just return the 514 // name for this locale, GetDisplayNameForLocale will just return the
511 // locale code. 515 // locale code.
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 887
884 const char* const* GetAcceptLanguageListForTesting() { 888 const char* const* GetAcceptLanguageListForTesting() {
885 return kAcceptLanguageList; 889 return kAcceptLanguageList;
886 } 890 }
887 891
888 size_t GetAcceptLanguageListSizeForTesting() { 892 size_t GetAcceptLanguageListSizeForTesting() {
889 return arraysize(kAcceptLanguageList); 893 return arraysize(kAcceptLanguageList);
890 } 894 }
891 895
892 } // namespace l10n_util 896 } // namespace l10n_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698