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

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

Issue 846373002: Move l10n_util's GetCanonicalLocal() function into base/i18n module. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix chromeos Created 5 years, 11 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
« no previous file with comments | « ui/base/l10n/l10n_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 303 }
304 }; 304 };
305 305
306 base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits> 306 base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits>
307 g_available_locales = LAZY_INSTANCE_INITIALIZER; 307 g_available_locales = LAZY_INSTANCE_INITIALIZER;
308 308
309 } // namespace 309 } // namespace
310 310
311 namespace l10n_util { 311 namespace l10n_util {
312 312
313 std::string GetCanonicalLocale(const std::string& locale) {
314 return base::i18n::GetCanonicalLocale(locale.c_str());
315 }
316
317 std::string GetLanguage(const std::string& locale) { 313 std::string GetLanguage(const std::string& locale) {
318 const std::string::size_type hyphen_pos = locale.find('-'); 314 const std::string::size_type hyphen_pos = locale.find('-');
319 return std::string(locale, 0, hyphen_pos); 315 return std::string(locale, 0, hyphen_pos);
320 } 316 }
321 317
322 bool CheckAndResolveLocale(const std::string& locale, 318 bool CheckAndResolveLocale(const std::string& locale,
323 std::string* resolved_locale) { 319 std::string* resolved_locale) {
324 #if defined(OS_MACOSX) 320 #if defined(OS_MACOSX)
325 NOTIMPLEMENTED(); 321 NOTIMPLEMENTED();
326 return false; 322 return false;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 423
428 // We only use --lang and the app pref on Windows. On Linux, we only 424 // We only use --lang and the app pref on Windows. On Linux, we only
429 // look at the LC_*/LANG environment variables. We do, however, pass --lang 425 // look at the LC_*/LANG environment variables. We do, however, pass --lang
430 // to renderer and plugin processes so they know what language the parent 426 // to renderer and plugin processes so they know what language the parent
431 // process decided to use. 427 // process decided to use.
432 428
433 #if defined(OS_WIN) 429 #if defined(OS_WIN)
434 430
435 // First, try the preference value. 431 // First, try the preference value.
436 if (!pref_locale.empty()) 432 if (!pref_locale.empty())
437 candidates.push_back(GetCanonicalLocale(pref_locale)); 433 candidates.push_back(base::i18n::GetCanonicalLocale(pref_locale));
438 434
439 // Next, try the overridden locale. 435 // Next, try the overridden locale.
440 const std::vector<std::string>& languages = l10n_util::GetLocaleOverrides(); 436 const std::vector<std::string>& languages = l10n_util::GetLocaleOverrides();
441 if (!languages.empty()) { 437 if (!languages.empty()) {
442 candidates.reserve(candidates.size() + languages.size()); 438 candidates.reserve(candidates.size() + languages.size());
443 std::transform(languages.begin(), languages.end(), 439 std::transform(languages.begin(), languages.end(),
444 std::back_inserter(candidates), &GetCanonicalLocale); 440 std::back_inserter(candidates),
441 &base::i18n::GetCanonicalLocale);
445 } else { 442 } else {
446 // If no override was set, defer to ICU 443 // If no override was set, defer to ICU
447 candidates.push_back(base::i18n::GetConfiguredLocale()); 444 candidates.push_back(base::i18n::GetConfiguredLocale());
448 } 445 }
449 446
450 #elif defined(OS_ANDROID) 447 #elif defined(OS_ANDROID)
451 448
452 // On Android, query java.util.Locale for the default locale. 449 // On Android, query java.util.Locale for the default locale.
453 candidates.push_back(base::android::GetDefaultLocale()); 450 candidates.push_back(base::android::GetDefaultLocale());
454 451
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 875
879 const char* const* GetAcceptLanguageListForTesting() { 876 const char* const* GetAcceptLanguageListForTesting() {
880 return kAcceptLanguageList; 877 return kAcceptLanguageList;
881 } 878 }
882 879
883 size_t GetAcceptLanguageListSizeForTesting() { 880 size_t GetAcceptLanguageListSizeForTesting() {
884 return arraysize(kAcceptLanguageList); 881 return arraysize(kAcceptLanguageList);
885 } 882 }
886 883
887 } // namespace l10n_util 884 } // namespace l10n_util
OLDNEW
« no previous file with comments | « ui/base/l10n/l10n_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698