diff options
author | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 22:54:46 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-19 22:54:46 +0000 |
commit | e6d34b118a34bdcaec0292aec39c2f5cc218575b (patch) | |
tree | 09c899bc4480355328e62876551d9e47e654e600 /app | |
parent | e8c45c7a2f1c130337578f562da0c1116916e987 (diff) | |
download | chromium_src-e6d34b118a34bdcaec0292aec39c2f5cc218575b.zip chromium_src-e6d34b118a34bdcaec0292aec39c2f5cc218575b.tar.gz chromium_src-e6d34b118a34bdcaec0292aec39c2f5cc218575b.tar.bz2 |
Merge r32515 from trunk to 249 branch
Mac language/locale cleanup
Effectively revert revision 28193 (http://codereview.chromium.org/258037), this makes Mac match the other platform for what at it's core is used for the chrome concept of locale.
For the ApplicationLanguage, the browser will end up with what Cocoa picks (same as before)
All other process types will honor the language they got on the command line when starting up.
When asked the apps language, have the same side effect as Windows and Linux has of pushing the language through to ICU also (so dates format right, etc.)
During browser startup, if someone passed a language, bail because Mac can't support that.
TEST=The tips on the NTP and the dates on the history page are in the same language at the UI.
BUG=26856
BUG=22727
Review URL: http://codereview.chromium.org/399086
TBR=thomasvl@chromium.org
Review URL: http://codereview.chromium.org/411005
git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@32564 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/l10n_util.cc | 39 | ||||
-rw-r--r-- | app/l10n_util_mac.h | 4 | ||||
-rw-r--r-- | app/l10n_util_mac.mm | 53 |
3 files changed, 84 insertions, 12 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc index d35f68d..f44ce37 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -25,6 +25,10 @@ #include <gtk/gtk.h> #endif +#if defined(OS_MACOSX) +#include "app/l10n_util_mac.h" +#endif + // TODO(playmobil): remove this undef once SkPostConfig.h is fixed. // skia/include/corecg/SkPostConfig.h #defines strcasecmp() so we can't use // base::strcasecmp() without #undefing it here. @@ -422,19 +426,16 @@ namespace l10n_util { // Represents the locale-specific text direction. static TextDirection g_text_direction = UNKNOWN_DIRECTION; -// On the Mac, we don't want to test preferences or ICU for the language, -// we want to use whatever Cocoa is using when it loaded the main nib file. -// It handles all the mapping and fallbacks for us, we just need to ask. -// See l10n_util_mac for that implementation. -#if !defined(OS_MACOSX) std::string GetApplicationLocale(const std::wstring& pref_locale) { +#if !defined(OS_MACOSX) + FilePath locale_path; PathService::Get(app::DIR_LOCALES, &locale_path); std::string resolved_locale; std::vector<std::string> candidates; const std::string system_locale = GetSystemLocale(); - // We only use --lang and the app pref on Windows. On Linux/Mac, we only + // We only use --lang and the app pref on Windows. On Linux, we only // look at the LC_*/LANG environment variables. We do, however, pass --lang // to renderer and plugin processes so they know what language the parent // process decided to use. @@ -482,8 +483,32 @@ std::string GetApplicationLocale(const std::wstring& pref_locale) { NOTREACHED(); return std::string(); -} + +#else // !defined(OS_MACOSX) + + // Use any override (Cocoa for the browser), otherwise use the command line + // argument. + std::string app_locale = l10n_util::GetLocaleOverride(); + if (app_locale.empty()) { + const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); + app_locale = parsed_command_line.GetSwitchValueASCII(switches::kLang); + } + + // The above should handle all of the cases Chrome normally hits, but for some + // unit tests, we need something to fall back too. + if (app_locale.empty()) + app_locale = "en-US"; + + // Windows/Linux call CheckAndResolveLocale which calls IsLocaleAvailable + // which calls SetICUDefaultLocale to let ICU use the same locale. Mac + // doesn't use a locale directory tree of resources (it uses Mac style + // resources), so mirror that ICU behavior by calling SetICUDefaultLocale + // directly. + UBool icu_set = SetICUDefaultLocale(app_locale); + DCHECK(icu_set); + return app_locale; #endif // !defined(OS_MACOSX) +} string16 GetDisplayNameForLocale(const std::string& locale_code, const std::string& display_locale, diff --git a/app/l10n_util_mac.h b/app/l10n_util_mac.h index 87ccb05..995d191 100644 --- a/app/l10n_util_mac.h +++ b/app/l10n_util_mac.h @@ -63,6 +63,10 @@ NSString* GetNSStringFWithFixup(int message_id, const string16& c, const string16& d); +// Support the override of the locale with the value from Cocoa. +void OverrideLocaleWithCocoaLocale(); +const std::string& GetLocaleOverride(); + } // namespace l10n_util #endif // APP_L10N_UTIL_MAC_H_ diff --git a/app/l10n_util_mac.mm b/app/l10n_util_mac.mm index fe09826..9861f14 100644 --- a/app/l10n_util_mac.mm +++ b/app/l10n_util_mac.mm @@ -5,14 +5,57 @@ #import <Foundation/Foundation.h> #include "app/l10n_util_mac.h" #include "base/sys_string_conversions.h" +#include "base/lazy_instance.h" + +namespace { + +class OverrideLocaleHolder { + public: + OverrideLocaleHolder() {} + const std::string& value() const { return value_; } + void set_value(const std::string override_value) { value_ = override_value; } + private: + DISALLOW_COPY_AND_ASSIGN(OverrideLocaleHolder); + std::string value_; +}; + +base::LazyInstance<OverrideLocaleHolder> + override_locale_holder(base::LINKER_INITIALIZED); + +} // namespace namespace l10n_util { -std::string GetApplicationLocale(const std::wstring& pref_locale) { - // NOTE: The Win/Linux version of this calls out to CheckAndResolveLocale - // to do some remapping. Since Mac is using real locales that Cocoa has - // to be able to load, that shouldn't be needed. - return [[[NSLocale currentLocale] localeIdentifier] UTF8String]; +const std::string& GetLocaleOverride() { + return override_locale_holder.Get().value(); +} + +void OverrideLocaleWithCocoaLocale() { + // NSBundle really should only be called on the main thread. + DCHECK([NSThread isMainThread]); + + // Chrome really only has one concept of locale, but Mac OS X has locale and + // language that can be set independently. After talking with Chrome UX folks + // (Cole), the best path from an experience point of view is to map the Mac OS + // X language into the Chrome locale. This way strings like "Yesterday" and + // "Today" are in the same language as raw dates like "March 20, 1999" (Chrome + // strings resources vs ICU generated strings). This also makes the Mac acts + // like other Chrome platforms. + NSArray* languageList = [[NSBundle mainBundle] preferredLocalizations]; + NSString* firstLocale = [languageList objectAtIndex:0]; + // Mac OS X uses "_" instead of "-", so swap to get a real locale value. + std::string locale_value = + [[firstLocale stringByReplacingOccurrencesOfString:@"_" + withString:@"-"] UTF8String]; + + // On disk the "en-US" resources are just "en" (http://crbug.com/25578), so + // the reverse mapping is done here to continue to feed Chrome the same values + // in all cases on all platforms. (l10n_util maps en to en-US if it gets + // passed this on the command line) + if (locale_value == "en") + locale_value = "en-US"; + + override_locale_holder.Get().set_value(locale_value); } // Remove the Windows-style accelerator marker and change "..." into an |