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

Side by Side Diff: app/l10n_util.cc

Issue 4139010: The UI language rather than the locale is now used to pick Chrome's language ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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
« no previous file with comments | « no previous file | app/l10n_util_win.h » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 6
7 #if defined(TOOLKIT_USES_GTK) 7 #if defined(TOOLKIT_USES_GTK)
8 #include <glib/gutils.h> 8 #include <glib/gutils.h>
9 #endif 9 #endif
10 10
11 #include <algorithm>
11 #include <cstdlib> 12 #include <cstdlib>
13 #include <iterator>
12 14
13 #include "app/app_paths.h" 15 #include "app/app_paths.h"
14 #include "app/l10n_util_collator.h" 16 #include "app/l10n_util_collator.h"
15 #include "app/resource_bundle.h" 17 #include "app/resource_bundle.h"
16 #include "base/command_line.h" 18 #include "base/command_line.h"
17 #include "base/file_util.h" 19 #include "base/file_util.h"
18 #include "base/i18n/file_util_icu.h" 20 #include "base/i18n/file_util_icu.h"
19 #include "base/i18n/rtl.h" 21 #include "base/i18n/rtl.h"
20 #include "base/path_service.h" 22 #include "base/path_service.h"
21 #include "base/scoped_ptr.h" 23 #include "base/scoped_ptr.h"
22 #include "base/string16.h" 24 #include "base/string16.h"
23 #include "base/string_number_conversions.h" 25 #include "base/string_number_conversions.h"
24 #include "base/string_split.h" 26 #include "base/string_split.h"
25 #include "base/sys_string_conversions.h" 27 #include "base/sys_string_conversions.h"
26 #include "base/utf_string_conversions.h" 28 #include "base/utf_string_conversions.h"
27 #include "build/build_config.h" 29 #include "build/build_config.h"
28 #include "gfx/canvas.h" 30 #include "gfx/canvas.h"
29 #include "unicode/rbbi.h" 31 #include "unicode/rbbi.h"
30 32
31 #if defined(OS_MACOSX) 33 #if defined(OS_MACOSX)
32 #include "app/l10n_util_mac.h" 34 #include "app/l10n_util_mac.h"
35 #elif defined(OS_WIN)
36 #include "app/l10n_util_win.h"
33 #endif 37 #endif
34 38
35 namespace { 39 namespace {
36 40
37 #if defined(OS_WIN) 41 #if defined(OS_WIN)
38 static const FilePath::CharType kLocaleFileExtension[] = L".dll"; 42 static const FilePath::CharType kLocaleFileExtension[] = L".dll";
39 #elif defined(OS_POSIX) 43 #elif defined(OS_POSIX)
40 static const FilePath::CharType kLocaleFileExtension[] = ".pak"; 44 static const FilePath::CharType kLocaleFileExtension[] = ".pak";
41 #endif 45 #endif
42 46
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // cases. 322 // cases.
319 void AdjustParagraphDirectionality(string16* paragraph) { 323 void AdjustParagraphDirectionality(string16* paragraph) {
320 #if defined(OS_LINUX) 324 #if defined(OS_LINUX)
321 if (base::i18n::IsRTL() && 325 if (base::i18n::IsRTL() &&
322 base::i18n::StringContainsStrongRTLChars(*paragraph)) { 326 base::i18n::StringContainsStrongRTLChars(*paragraph)) {
323 paragraph->insert(0, 1, static_cast<char16>(base::i18n::kRightToLeftMark)); 327 paragraph->insert(0, 1, static_cast<char16>(base::i18n::kRightToLeftMark));
324 } 328 }
325 #endif 329 #endif
326 } 330 }
327 331
332 std::string GetCanonicalLocale(const std::string& locale) {
333 return base::i18n::GetCanonicalLocale(locale.c_str());
334 }
335
328 } // namespace 336 } // namespace
329 337
330 namespace l10n_util { 338 namespace l10n_util {
331 339
332 std::string GetApplicationLocale(const std::string& pref_locale) { 340 std::string GetApplicationLocale(const std::string& pref_locale) {
333 #if defined(OS_MACOSX) 341 #if defined(OS_MACOSX)
334 342
335 // Use any override (Cocoa for the browser), otherwise use the preference 343 // Use any override (Cocoa for the browser), otherwise use the preference
336 // passed to the function. 344 // passed to the function.
337 std::string app_locale = l10n_util::GetLocaleOverride(); 345 std::string app_locale = l10n_util::GetLocaleOverride();
(...skipping 24 matching lines...) Expand all
362 // look at the LC_*/LANG environment variables. We do, however, pass --lang 370 // look at the LC_*/LANG environment variables. We do, however, pass --lang
363 // to renderer and plugin processes so they know what language the parent 371 // to renderer and plugin processes so they know what language the parent
364 // process decided to use. 372 // process decided to use.
365 373
366 #if defined(OS_WIN) 374 #if defined(OS_WIN)
367 375
368 // First, try the preference value. 376 // First, try the preference value.
369 if (!pref_locale.empty()) 377 if (!pref_locale.empty())
370 candidates.push_back(pref_locale); 378 candidates.push_back(pref_locale);
371 379
372 // Next, try the system locale. 380 // Next, try the overridden locale.
373 candidates.push_back(base::i18n::GetConfiguredLocale()); 381 const std::vector<std::string>& languages = l10n_util::GetLocaleOverrides();
382 if (!languages.empty()) {
383 candidates.reserve(candidates.size() + languages.size());
384 std::transform(languages.begin(), languages.end(),
385 std::back_inserter(candidates), &GetCanonicalLocale);
386 } else {
387 // If no override was set, defer to ICU
388 candidates.push_back(base::i18n::GetConfiguredLocale());
389 }
374 390
375 #elif defined(OS_CHROMEOS) 391 #elif defined(OS_CHROMEOS)
376 392
377 // On ChromeOS, use the application locale preference. 393 // On ChromeOS, use the application locale preference.
378 if (!pref_locale.empty()) 394 if (!pref_locale.empty())
379 candidates.push_back(pref_locale); 395 candidates.push_back(pref_locale);
380 396
381 #elif defined(OS_POSIX) && defined(TOOLKIT_USES_GTK) 397 #elif defined(OS_POSIX) && defined(TOOLKIT_USES_GTK)
382 398
383 // GLib implements correct environment variable parsing with 399 // GLib implements correct environment variable parsing with
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { 870 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) {
855 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) 871 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale))
856 // TODO(jungshik) : Put them at the of the list with language codes 872 // TODO(jungshik) : Put them at the of the list with language codes
857 // enclosed by brackets instead of skipping. 873 // enclosed by brackets instead of skipping.
858 continue; 874 continue;
859 locale_codes->push_back(kAcceptLanguageList[i]); 875 locale_codes->push_back(kAcceptLanguageList[i]);
860 } 876 }
861 } 877 }
862 878
863 } // namespace l10n_util 879 } // namespace l10n_util
OLDNEW
« no previous file with comments | « no previous file | app/l10n_util_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698