1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Foundation/Foundation.h>
#include "app/l10n_util_mac.h"
#include "base/sys_string_conversions.h"
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];
}
// Remove the Windows-style accelerator marker and change "..." into an
// ellipsis. Returns the result in an autoreleased NSString.
NSString* FixUpWindowsStyleLabel(const string16& label) {
const char16 kEllipsisUTF16 = 0x2026;
string16 ret;
size_t label_len = label.length();
ret.reserve(label_len);
for (size_t i = 0; i < label_len; ++i) {
char16 c = label[i];
if (c == '&') {
if (i + 1 < label_len && label[i + 1] == '&') {
ret.push_back(c);
++i;
}
} else if (c == '.' && i + 2 < label_len && label[i + 1] == '.'
&& label[i + 2] == '.') {
ret.push_back(kEllipsisUTF16);
i += 2;
} else {
ret.push_back(c);
}
}
return base::SysUTF16ToNSString(ret);
}
NSString* GetNSString(int message_id) {
return base::SysUTF16ToNSString(l10n_util::GetStringUTF16(message_id));
}
NSString* GetNSStringF(int message_id,
const string16& a) {
return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
a));
}
NSString* GetNSStringF(int message_id,
const string16& a,
const string16& b) {
return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
a, b));
}
NSString* GetNSStringF(int message_id,
const string16& a,
const string16& b,
const string16& c) {
return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
a, b, c));
}
NSString* GetNSStringF(int message_id,
const string16& a,
const string16& b,
const string16& c,
const string16& d) {
return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
a, b, c, d));
}
NSString* GetNSStringWithFixup(int message_id) {
return FixUpWindowsStyleLabel(l10n_util::GetStringUTF16(message_id));
}
NSString* GetNSStringFWithFixup(int message_id,
const string16& a) {
return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
a));
}
NSString* GetNSStringFWithFixup(int message_id,
const string16& a,
const string16& b) {
return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
a, b));
}
NSString* GetNSStringFWithFixup(int message_id,
const string16& a,
const string16& b,
const string16& c) {
return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
a, b, c));
}
NSString* GetNSStringFWithFixup(int message_id,
const string16& a,
const string16& b,
const string16& c,
const string16& d) {
return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
a, b, c, d));
}
} // namespace l10n_util
|