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

Side by Side Diff: app/l10n_util.cc

Issue 399086: Mac language/locale cleanup... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 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_mac.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include <cstdlib> 7 #include <cstdlib>
8 #include "app/app_paths.h" 8 #include "app/app_paths.h"
9 #include "app/app_switches.h" 9 #include "app/app_switches.h"
10 #include "app/gfx/canvas.h" 10 #include "app/gfx/canvas.h"
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/i18n/file_util_icu.h" 14 #include "base/i18n/file_util_icu.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/scoped_ptr.h" 16 #include "base/scoped_ptr.h"
17 #include "base/string16.h" 17 #include "base/string16.h"
18 #include "base/string_piece.h" 18 #include "base/string_piece.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/sys_string_conversions.h" 20 #include "base/sys_string_conversions.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "unicode/uscript.h" 22 #include "unicode/uscript.h"
23 23
24 #if defined(TOOLKIT_GTK) 24 #if defined(TOOLKIT_GTK)
25 #include <gtk/gtk.h> 25 #include <gtk/gtk.h>
26 #endif 26 #endif
27 27
28 #if defined(OS_MACOSX)
29 #include "app/l10n_util_mac.h"
30 #endif
31
28 // TODO(playmobil): remove this undef once SkPostConfig.h is fixed. 32 // TODO(playmobil): remove this undef once SkPostConfig.h is fixed.
29 // skia/include/corecg/SkPostConfig.h #defines strcasecmp() so we can't use 33 // skia/include/corecg/SkPostConfig.h #defines strcasecmp() so we can't use
30 // base::strcasecmp() without #undefing it here. 34 // base::strcasecmp() without #undefing it here.
31 #undef strcasecmp 35 #undef strcasecmp
32 36
33 namespace { 37 namespace {
34 38
35 #if defined(OS_WIN) 39 #if defined(OS_WIN)
36 static const FilePath::CharType kLocaleFileExtension[] = L".dll"; 40 static const FilePath::CharType kLocaleFileExtension[] = L".dll";
37 #elif defined(OS_POSIX) 41 #elif defined(OS_POSIX)
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 419 }
416 #endif 420 #endif
417 421
418 } // namespace 422 } // namespace
419 423
420 namespace l10n_util { 424 namespace l10n_util {
421 425
422 // Represents the locale-specific text direction. 426 // Represents the locale-specific text direction.
423 static TextDirection g_text_direction = UNKNOWN_DIRECTION; 427 static TextDirection g_text_direction = UNKNOWN_DIRECTION;
424 428
425 // On the Mac, we don't want to test preferences or ICU for the language, 429 std::string GetApplicationLocale(const std::wstring& pref_locale) {
426 // we want to use whatever Cocoa is using when it loaded the main nib file.
427 // It handles all the mapping and fallbacks for us, we just need to ask.
428 // See l10n_util_mac for that implementation.
429 #if !defined(OS_MACOSX) 430 #if !defined(OS_MACOSX)
430 std::string GetApplicationLocale(const std::wstring& pref_locale) { 431
431 FilePath locale_path; 432 FilePath locale_path;
432 PathService::Get(app::DIR_LOCALES, &locale_path); 433 PathService::Get(app::DIR_LOCALES, &locale_path);
433 std::string resolved_locale; 434 std::string resolved_locale;
434 std::vector<std::string> candidates; 435 std::vector<std::string> candidates;
435 const std::string system_locale = GetSystemLocale(); 436 const std::string system_locale = GetSystemLocale();
436 437
437 // We only use --lang and the app pref on Windows. On Linux/Mac, we only 438 // We only use --lang and the app pref on Windows. On Linux, we only
438 // look at the LC_*/LANG environment variables. We do, however, pass --lang 439 // look at the LC_*/LANG environment variables. We do, however, pass --lang
439 // to renderer and plugin processes so they know what language the parent 440 // to renderer and plugin processes so they know what language the parent
440 // process decided to use. 441 // process decided to use.
441 #if defined(OS_WIN) 442 #if defined(OS_WIN)
442 // First, check to see if there's a --lang flag. 443 // First, check to see if there's a --lang flag.
443 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 444 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
444 const std::string& lang_arg = WideToASCII( 445 const std::string& lang_arg = WideToASCII(
445 parsed_command_line.GetSwitchValue(switches::kLang)); 446 parsed_command_line.GetSwitchValue(switches::kLang));
446 if (!lang_arg.empty()) 447 if (!lang_arg.empty())
447 candidates.push_back(lang_arg); 448 candidates.push_back(lang_arg);
(...skipping 27 matching lines...) Expand all
475 476
476 // Fallback on en-US. 477 // Fallback on en-US.
477 const std::string fallback_locale("en-US"); 478 const std::string fallback_locale("en-US");
478 if (IsLocaleAvailable(fallback_locale, locale_path)) 479 if (IsLocaleAvailable(fallback_locale, locale_path))
479 return fallback_locale; 480 return fallback_locale;
480 481
481 // No locale data file was found; we shouldn't get here. 482 // No locale data file was found; we shouldn't get here.
482 NOTREACHED(); 483 NOTREACHED();
483 484
484 return std::string(); 485 return std::string();
486
487 #else // !defined(OS_MACOSX)
488
489 // Use any override (Cocoa for the browser), otherwise use the command line
490 // argument.
491 std::string app_locale = l10n_util::GetLocaleOverride();
492 if (app_locale.empty()) {
493 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
494 app_locale = parsed_command_line.GetSwitchValueASCII(switches::kLang);
495 }
496
497 // The above should handle all of the cases Chrome normally hits, but for some
498 // unit tests, we need something to fall back too.
499 if (app_locale.empty())
500 app_locale = "en-US";
501
502 // Windows/Linux call CheckAndResolveLocale which calls IsLocaleAvailable
503 // which calls SetICUDefaultLocale to let ICU use the same locale. Mac
504 // doesn't use a locale directory tree of resources (it uses Mac style
505 // resources), so mirror that ICU behavior by calling SetICUDefaultLocale
506 // directly.
507 UBool icu_set = SetICUDefaultLocale(app_locale);
508 DCHECK(icu_set);
509 return app_locale;
510 #endif // !defined(OS_MACOSX)
485 } 511 }
486 #endif // !defined(OS_MACOSX)
487 512
488 string16 GetDisplayNameForLocale(const std::string& locale_code, 513 string16 GetDisplayNameForLocale(const std::string& locale_code,
489 const std::string& display_locale, 514 const std::string& display_locale,
490 bool is_for_ui) { 515 bool is_for_ui) {
491 UErrorCode error = U_ZERO_ERROR; 516 UErrorCode error = U_ZERO_ERROR;
492 const int buffer_size = 1024; 517 const int buffer_size = 1024;
493 518
494 string16 display_name; 519 string16 display_name;
495 int actual_size = uloc_getDisplayName(locale_code.c_str(), 520 int actual_size = uloc_getDisplayName(locale_code.c_str(),
496 display_locale.c_str(), 521 display_locale.c_str(),
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 } 1060 }
1036 1061
1037 void BiDiLineIterator::GetLogicalRun(int start, 1062 void BiDiLineIterator::GetLogicalRun(int start,
1038 int* end, 1063 int* end,
1039 UBiDiLevel* level) { 1064 UBiDiLevel* level) {
1040 DCHECK(bidi_ != NULL); 1065 DCHECK(bidi_ != NULL);
1041 ubidi_getLogicalRun(bidi_, start, end, level); 1066 ubidi_getLogicalRun(bidi_, start, end, level);
1042 } 1067 }
1043 1068
1044 } // namespace l10n_util 1069 } // namespace l10n_util
OLDNEW
« no previous file with comments | « no previous file | app/l10n_util_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698