| OLD | NEW |
| 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 #include <cstdlib> | 7 #include <cstdlib> |
| 8 | 8 |
| 9 #include "app/app_paths.h" | 9 #include "app/app_paths.h" |
| 10 #include "app/app_switches.h" | 10 #include "app/app_switches.h" |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 PathService::Get(app::DIR_LOCALES, &locale_path); | 374 PathService::Get(app::DIR_LOCALES, &locale_path); |
| 375 std::string resolved_locale; | 375 std::string resolved_locale; |
| 376 std::vector<std::string> candidates; | 376 std::vector<std::string> candidates; |
| 377 const std::string system_locale = GetSystemLocale(); | 377 const std::string system_locale = GetSystemLocale(); |
| 378 | 378 |
| 379 // We only use --lang and the app pref on Windows. On Linux, we only | 379 // We only use --lang and the app pref on Windows. On Linux, we only |
| 380 // look at the LC_*/LANG environment variables. We do, however, pass --lang | 380 // look at the LC_*/LANG environment variables. We do, however, pass --lang |
| 381 // to renderer and plugin processes so they know what language the parent | 381 // to renderer and plugin processes so they know what language the parent |
| 382 // process decided to use. | 382 // process decided to use. |
| 383 #if defined(OS_WIN) | 383 #if defined(OS_WIN) |
| 384 // First, check to see if there's a --lang flag. | 384 // First, try the preference value. |
| 385 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | |
| 386 const std::string& lang_arg = | |
| 387 parsed_command_line.GetSwitchValueASCII(switches::kLang); | |
| 388 if (!lang_arg.empty()) | |
| 389 candidates.push_back(lang_arg); | |
| 390 | |
| 391 // Second, try user prefs. | |
| 392 if (!pref_locale.empty()) | 385 if (!pref_locale.empty()) |
| 393 candidates.push_back(WideToASCII(pref_locale)); | 386 candidates.push_back(WideToASCII(pref_locale)); |
| 394 | 387 |
| 395 // Next, try the system locale. | 388 // Next, try the system locale. |
| 396 candidates.push_back(system_locale); | 389 candidates.push_back(system_locale); |
| 397 | 390 |
| 398 #elif defined(OS_CHROMEOS) | 391 #elif defined(OS_CHROMEOS) |
| 399 // We use --lang on chroemos for debugging/troubleshooting purpose. | 392 // On ChromeOS, use the application locale preference. |
| 400 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | |
| 401 const std::string& lang_arg = | |
| 402 parsed_command_line.GetSwitchValueASCII(switches::kLang); | |
| 403 if (!lang_arg.empty()) | |
| 404 candidates.push_back(lang_arg); | |
| 405 | |
| 406 // On ChromeOS, try user prefs. This restores the locale used by the | |
| 407 // previous run of the OS. | |
| 408 if (!pref_locale.empty()) | 393 if (!pref_locale.empty()) |
| 409 candidates.push_back(WideToASCII(pref_locale)); | 394 candidates.push_back(WideToASCII(pref_locale)); |
| 410 | 395 |
| 411 #elif defined(OS_POSIX) | 396 #elif defined(OS_POSIX) |
| 412 // On POSIX, we also check LANGUAGE environment variable, which is supported | 397 // On POSIX, we also check LANGUAGE environment variable, which is supported |
| 413 // by gettext to specify a priority list of prefered languages. | 398 // by gettext to specify a priority list of prefered languages. |
| 414 const char* env_language = ::getenv("LANGUAGE"); | 399 const char* env_language = ::getenv("LANGUAGE"); |
| 415 if (env_language) | 400 if (env_language) |
| 416 SplitAndNormalizeLanguageList(env_language, &candidates); | 401 SplitAndNormalizeLanguageList(env_language, &candidates); |
| 417 | 402 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 438 return fallback_locale; | 423 return fallback_locale; |
| 439 } | 424 } |
| 440 | 425 |
| 441 // No locale data file was found; we shouldn't get here. | 426 // No locale data file was found; we shouldn't get here. |
| 442 NOTREACHED(); | 427 NOTREACHED(); |
| 443 | 428 |
| 444 return std::string(); | 429 return std::string(); |
| 445 | 430 |
| 446 #else // !defined(OS_MACOSX) | 431 #else // !defined(OS_MACOSX) |
| 447 | 432 |
| 448 // Use any override (Cocoa for the browser), otherwise use the command line | 433 // Use any override (Cocoa for the browser), otherwise use the preference |
| 449 // argument. | 434 // passed to the function. |
| 450 std::string app_locale = l10n_util::GetLocaleOverride(); | 435 std::string app_locale = l10n_util::GetLocaleOverride(); |
| 451 if (app_locale.empty()) { | 436 if (app_locale.empty()) { |
| 452 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 437 app_locale = WideToASCII(pref_locale); |
| 453 app_locale = parsed_command_line.GetSwitchValueASCII(switches::kLang); | |
| 454 } | 438 } |
| 455 | 439 |
| 456 // The above should handle all of the cases Chrome normally hits, but for some | 440 // The above should handle all of the cases Chrome normally hits, but for some |
| 457 // unit tests, we need something to fall back too. | 441 // unit tests, we need something to fall back too. |
| 458 if (app_locale.empty()) | 442 if (app_locale.empty()) |
| 459 app_locale = "en-US"; | 443 app_locale = "en-US"; |
| 460 | 444 |
| 461 // Windows/Linux call SetICUDefaultLocale after determining the actual locale | 445 // Windows/Linux call SetICUDefaultLocale after determining the actual locale |
| 462 // with CheckAndResolveLocal to make ICU APIs work in that locale. | 446 // with CheckAndResolveLocal to make ICU APIs work in that locale. |
| 463 // Mac doesn't use a locale directory tree of resources (it uses Mac style | 447 // Mac doesn't use a locale directory tree of resources (it uses Mac style |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 853 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { |
| 870 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) | 854 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) |
| 871 // TODO(jungshik) : Put them at the of the list with language codes | 855 // TODO(jungshik) : Put them at the of the list with language codes |
| 872 // enclosed by brackets instead of skipping. | 856 // enclosed by brackets instead of skipping. |
| 873 continue; | 857 continue; |
| 874 locale_codes->push_back(kAcceptLanguageList[i]); | 858 locale_codes->push_back(kAcceptLanguageList[i]); |
| 875 } | 859 } |
| 876 } | 860 } |
| 877 | 861 |
| 878 } // namespace l10n_util | 862 } // namespace l10n_util |
| OLD | NEW |