OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
6 #include "app/l10n_util_mac.h" | 6 #include "app/l10n_util_mac.h" |
7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
| 8 #include "base/lazy_instance.h" |
| 9 |
| 10 namespace { |
| 11 |
| 12 class OverrideLocaleHolder { |
| 13 public: |
| 14 OverrideLocaleHolder() {} |
| 15 const std::string& value() const { return value_; } |
| 16 void set_value(const std::string override_value) { value_ = override_value; } |
| 17 private: |
| 18 DISALLOW_COPY_AND_ASSIGN(OverrideLocaleHolder); |
| 19 std::string value_; |
| 20 }; |
| 21 |
| 22 base::LazyInstance<OverrideLocaleHolder> |
| 23 override_locale_holder(base::LINKER_INITIALIZED); |
| 24 |
| 25 } // namespace |
8 | 26 |
9 namespace l10n_util { | 27 namespace l10n_util { |
10 | 28 |
11 std::string GetApplicationLocale(const std::wstring& pref_locale) { | 29 const std::string& GetLocaleOverride() { |
12 // NOTE: The Win/Linux version of this calls out to CheckAndResolveLocale | 30 return override_locale_holder.Get().value(); |
13 // to do some remapping. Since Mac is using real locales that Cocoa has | 31 } |
14 // to be able to load, that shouldn't be needed. | 32 |
15 return [[[NSLocale currentLocale] localeIdentifier] UTF8String]; | 33 void OverrideLocaleWithCocoaLocale() { |
| 34 // NSBundle really should only be called on the main thread. |
| 35 DCHECK([NSThread isMainThread]); |
| 36 |
| 37 // Chrome really only has one concept of locale, but Mac OS X has locale and |
| 38 // language that can be set independently. After talking with Chrome UX folks |
| 39 // (Cole), the best path from an experience point of view is to map the Mac OS |
| 40 // X language into the Chrome locale. This way strings like "Yesterday" and |
| 41 // "Today" are in the same language as raw dates like "March 20, 1999" (Chrome |
| 42 // strings resources vs ICU generated strings). This also makes the Mac acts |
| 43 // like other Chrome platforms. |
| 44 NSArray* languageList = [[NSBundle mainBundle] preferredLocalizations]; |
| 45 NSString* firstLocale = [languageList objectAtIndex:0]; |
| 46 // Mac OS X uses "_" instead of "-", so swap to get a real locale value. |
| 47 std::string locale_value = |
| 48 [[firstLocale stringByReplacingOccurrencesOfString:@"_" |
| 49 withString:@"-"] UTF8String]; |
| 50 |
| 51 // On disk the "en-US" resources are just "en" (http://crbug.com/25578), so |
| 52 // the reverse mapping is done here to continue to feed Chrome the same values |
| 53 // in all cases on all platforms. (l10n_util maps en to en-US if it gets |
| 54 // passed this on the command line) |
| 55 if (locale_value == "en") |
| 56 locale_value = "en-US"; |
| 57 |
| 58 override_locale_holder.Get().set_value(locale_value); |
16 } | 59 } |
17 | 60 |
18 // Remove the Windows-style accelerator marker and change "..." into an | 61 // Remove the Windows-style accelerator marker and change "..." into an |
19 // ellipsis. Returns the result in an autoreleased NSString. | 62 // ellipsis. Returns the result in an autoreleased NSString. |
20 NSString* FixUpWindowsStyleLabel(const string16& label) { | 63 NSString* FixUpWindowsStyleLabel(const string16& label) { |
21 const char16 kEllipsisUTF16 = 0x2026; | 64 const char16 kEllipsisUTF16 = 0x2026; |
22 string16 ret; | 65 string16 ret; |
23 size_t label_len = label.length(); | 66 size_t label_len = label.length(); |
24 ret.reserve(label_len); | 67 ret.reserve(label_len); |
25 for (size_t i = 0; i < label_len; ++i) { | 68 for (size_t i = 0; i < label_len; ++i) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 const string16& a, | 147 const string16& a, |
105 const string16& b, | 148 const string16& b, |
106 const string16& c, | 149 const string16& c, |
107 const string16& d) { | 150 const string16& d) { |
108 return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id, | 151 return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id, |
109 a, b, c, d)); | 152 a, b, c, d)); |
110 } | 153 } |
111 | 154 |
112 | 155 |
113 } // namespace l10n_util | 156 } // namespace l10n_util |
OLD | NEW |