OLD | NEW |
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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // to this file and we know where/when it's called. | 44 // to this file and we know where/when it's called. |
45 Locale locale = Locale::getDefault(); | 45 Locale locale = Locale::getDefault(); |
46 const char* language = locale.getLanguage(); | 46 const char* language = locale.getLanguage(); |
47 const char* country = locale.getCountry(); | 47 const char* country = locale.getCountry(); |
48 DCHECK(language); | 48 DCHECK(language); |
49 *lang = language; | 49 *lang = language; |
50 *region = country; | 50 *region = country; |
51 } | 51 } |
52 | 52 |
53 // Convert Chrome locale name to ICU locale name | 53 // Convert Chrome locale name to ICU locale name |
54 std::string ICULocaleName(const std::wstring& locale_string) { | 54 std::string ICULocaleName(const std::string& locale_string) { |
55 // If not Spanish, just return it. | 55 // If not Spanish, just return it. |
56 if (locale_string.substr(0, 2) != L"es") | 56 if (locale_string.substr(0, 2) != "es") |
57 return WideToASCII(locale_string); | 57 return locale_string; |
58 // Expand es to es-ES. | 58 // Expand es to es-ES. |
59 if (LowerCaseEqualsASCII(locale_string, "es")) | 59 if (LowerCaseEqualsASCII(locale_string, "es")) |
60 return "es-ES"; | 60 return "es-ES"; |
61 // Map es-419 (Latin American Spanish) to es-FOO depending on the system | 61 // Map es-419 (Latin American Spanish) to es-FOO depending on the system |
62 // locale. If it's es-RR other than es-ES, map to es-RR. Otherwise, map | 62 // locale. If it's es-RR other than es-ES, map to es-RR. Otherwise, map |
63 // to es-MX (the most populous in Spanish-speaking Latin America). | 63 // to es-MX (the most populous in Spanish-speaking Latin America). |
64 if (LowerCaseEqualsASCII(locale_string, "es-419")) { | 64 if (LowerCaseEqualsASCII(locale_string, "es-419")) { |
65 std::string lang, region; | 65 std::string lang, region; |
66 GetLanguageAndRegionFromOS(&lang, ®ion); | 66 GetLanguageAndRegionFromOS(&lang, ®ion); |
67 if (LowerCaseEqualsASCII(lang, "es") && | 67 if (LowerCaseEqualsASCII(lang, "es") && |
68 !LowerCaseEqualsASCII(region, "es")) { | 68 !LowerCaseEqualsASCII(region, "es")) { |
69 lang.append("-"); | 69 lang.append("-"); |
70 lang.append(region); | 70 lang.append(region); |
71 return lang; | 71 return lang; |
72 } | 72 } |
73 return "es-MX"; | 73 return "es-MX"; |
74 } | 74 } |
75 // Currently, Chrome has only "es" and "es-419", but later we may have | 75 // Currently, Chrome has only "es" and "es-419", but later we may have |
76 // more specific "es-RR". | 76 // more specific "es-RR". |
77 return WideToASCII(locale_string); | 77 return locale_string; |
78 } | 78 } |
79 | 79 |
80 // Sets the default locale of ICU. | 80 // Sets the default locale of ICU. |
81 // When the application locale (UI locale) of Chrome is specified with | 81 // When the application locale (UI locale) of Chrome is specified with |
82 // '--lang' command line flag or 'intl.app_locale' entry in the "Preferences", | 82 // '--lang' command line flag or 'intl.app_locale' entry in the "Preferences", |
83 // the default locale of ICU need to be changed to match the application locale | 83 // the default locale of ICU need to be changed to match the application locale |
84 // so that ICU functions work correctly in a locale-dependent manner. | 84 // so that ICU functions work correctly in a locale-dependent manner. |
85 // This is handy in that we don't have to call GetApplicationLocale() | 85 // This is handy in that we don't have to call GetApplicationLocale() |
86 // everytime we call locale-dependent ICU APIs as long as we make sure | 86 // everytime we call locale-dependent ICU APIs as long as we make sure |
87 // that this is called before any locale-dependent API is called. | 87 // that this is called before any locale-dependent API is called. |
88 UBool SetICUDefaultLocale(const std::wstring& locale_string) { | 88 UBool SetICUDefaultLocale(const std::string& locale_string) { |
89 Locale locale(ICULocaleName(locale_string).c_str()); | 89 Locale locale(ICULocaleName(locale_string).c_str()); |
90 UErrorCode error_code = U_ZERO_ERROR; | 90 UErrorCode error_code = U_ZERO_ERROR; |
91 Locale::setDefault(locale, error_code); | 91 Locale::setDefault(locale, error_code); |
92 // This return value is actually bogus because Locale object is | 92 // This return value is actually bogus because Locale object is |
93 // an ID and setDefault seems to always succeed (regardless of the | 93 // an ID and setDefault seems to always succeed (regardless of the |
94 // presence of actual locale data). However, | 94 // presence of actual locale data). However, |
95 // it does not hurt to have it as a sanity check. | 95 // it does not hurt to have it as a sanity check. |
96 return U_SUCCESS(error_code); | 96 return U_SUCCESS(error_code); |
97 } | 97 } |
98 | 98 |
(...skipping 12 matching lines...) Expand all Loading... |
111 // has to be added manually in GetAvailableLocales(). | 111 // has to be added manually in GetAvailableLocales(). |
112 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_")) | 112 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_")) |
113 return true; | 113 return true; |
114 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { | 114 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) { |
115 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0) | 115 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0) |
116 return true; | 116 return true; |
117 } | 117 } |
118 return false; | 118 return false; |
119 } | 119 } |
120 | 120 |
121 bool IsLocaleAvailable(const std::wstring& locale, | 121 bool IsLocaleAvailable(const std::string& locale, |
122 const std::wstring& locale_path) { | 122 const FilePath& locale_path) { |
123 std::wstring test_locale = locale; | |
124 // If locale has any illegal characters in it, we don't want to try to | 123 // If locale has any illegal characters in it, we don't want to try to |
125 // load it because it may be pointing outside the locale data file directory. | 124 // load it because it may be pointing outside the locale data file directory. |
126 file_util::ReplaceIllegalCharacters(&test_locale, ' '); | 125 if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale))) |
127 if (test_locale != locale) | |
128 return false; | 126 return false; |
129 | 127 |
130 if (!l10n_util::IsLocaleSupportedByOS(locale)) | 128 if (!l10n_util::IsLocaleSupportedByOS(locale)) |
131 return false; | 129 return false; |
132 | 130 |
133 FilePath test_path = FilePath::FromWStringHack(locale_path) | 131 FilePath test_path = locale_path; |
134 .Append(FilePath::FromWStringHack(locale)) | 132 test_path.AppendASCII(locale).ReplaceExtension(kLocaleFileExtension); |
135 .ReplaceExtension(kLocaleFileExtension); | |
136 return file_util::PathExists(test_path) && SetICUDefaultLocale(locale); | 133 return file_util::PathExists(test_path) && SetICUDefaultLocale(locale); |
137 } | 134 } |
138 | 135 |
139 bool CheckAndResolveLocale(const std::wstring& locale, | 136 bool CheckAndResolveLocale(const std::string& locale, |
140 const std::wstring& locale_path, | 137 const FilePath& locale_path, |
141 std::wstring* resolved_locale) { | 138 std::string* resolved_locale) { |
142 if (IsLocaleAvailable(locale, locale_path)) { | 139 if (IsLocaleAvailable(locale, locale_path)) { |
143 *resolved_locale = locale; | 140 *resolved_locale = locale; |
144 return true; | 141 return true; |
145 } | 142 } |
146 // If the locale matches language but not country, use that instead. | 143 // If the locale matches language but not country, use that instead. |
147 // TODO(jungshik) : Nothing is done about languages that Chrome | 144 // TODO(jungshik) : Nothing is done about languages that Chrome |
148 // does not support but available on Windows. We fall | 145 // does not support but available on Windows. We fall |
149 // back to en-US in GetApplicationLocale so that it's a not critical, | 146 // back to en-US in GetApplicationLocale so that it's a not critical, |
150 // but we can do better. | 147 // but we can do better. |
151 std::wstring::size_type hyphen_pos = locale.find(L'-'); | 148 std::string::size_type hyphen_pos = locale.find(L'-'); |
152 if (hyphen_pos != std::wstring::npos && hyphen_pos > 0) { | 149 if (hyphen_pos != std::string::npos && hyphen_pos > 0) { |
153 std::wstring lang(locale, 0, hyphen_pos); | 150 std::string lang(locale, 0, hyphen_pos); |
154 std::wstring region(locale, hyphen_pos + 1); | 151 std::string region(locale, hyphen_pos + 1); |
155 std::wstring tmp_locale(lang); | 152 std::string tmp_locale(lang); |
156 // Map es-RR other than es-ES to es-419 (Chrome's Latin American | 153 // Map es-RR other than es-ES to es-419 (Chrome's Latin American |
157 // Spanish locale). | 154 // Spanish locale). |
158 if (LowerCaseEqualsASCII(lang, "es") && !LowerCaseEqualsASCII(region, "es")) | 155 if (LowerCaseEqualsASCII(lang, "es") && !LowerCaseEqualsASCII(region, "es")) |
159 tmp_locale.append(L"-419"); | 156 tmp_locale.append("-419"); |
160 else if (LowerCaseEqualsASCII(lang, "zh")) { | 157 else if (LowerCaseEqualsASCII(lang, "zh")) { |
161 // Map zh-HK and zh-MK to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. | 158 // Map zh-HK and zh-MK to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. |
162 if (LowerCaseEqualsASCII(region, "hk") || | 159 if (LowerCaseEqualsASCII(region, "hk") || |
163 LowerCaseEqualsASCII(region, "mk")) { | 160 LowerCaseEqualsASCII(region, "mk")) { |
164 tmp_locale.append(L"-TW"); | 161 tmp_locale.append("-TW"); |
165 } else { | 162 } else { |
166 tmp_locale.append(L"-CN"); | 163 tmp_locale.append("-CN"); |
167 } | 164 } |
168 } | 165 } |
169 if (IsLocaleAvailable(tmp_locale, locale_path)) { | 166 if (IsLocaleAvailable(tmp_locale, locale_path)) { |
170 resolved_locale->swap(tmp_locale); | 167 resolved_locale->swap(tmp_locale); |
171 return true; | 168 return true; |
172 } | 169 } |
173 } | 170 } |
174 | 171 |
175 // Google updater uses no, iw and en for our nb, he, and en-US. | 172 // Google updater uses no, iw and en for our nb, he, and en-US. |
176 // We need to map them to our codes. | 173 // We need to map them to our codes. |
177 struct { | 174 struct { |
178 const char* source; | 175 const char* source; |
179 const wchar_t* dest;} alias_map[] = { | 176 const char* dest;} alias_map[] = { |
180 {"no", L"nb"}, | 177 {"no", "nb"}, |
181 {"tl", L"fil"}, | 178 {"tl", "fil"}, |
182 {"iw", L"he"}, | 179 {"iw", "he"}, |
183 {"en", L"en-US"}, | 180 {"en", "en-US"}, |
184 }; | 181 }; |
185 | 182 |
186 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) { | 183 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) { |
187 if (LowerCaseEqualsASCII(locale, alias_map[i].source)) { | 184 if (LowerCaseEqualsASCII(locale, alias_map[i].source)) { |
188 std::wstring tmp_locale(alias_map[i].dest); | 185 std::string tmp_locale(alias_map[i].dest); |
189 if (IsLocaleAvailable(tmp_locale, locale_path)) { | 186 if (IsLocaleAvailable(tmp_locale, locale_path)) { |
190 resolved_locale->swap(tmp_locale); | 187 resolved_locale->swap(tmp_locale); |
191 return true; | 188 return true; |
192 } | 189 } |
193 } | 190 } |
194 } | 191 } |
195 | 192 |
196 return false; | 193 return false; |
197 } | 194 } |
198 | 195 |
199 // Get the locale of the operating system. The return value is of the form | 196 // Get the locale of the operating system. The return value is of the form |
200 // language[-country] (e.g., en-US) where the language is the 2 letter code from | 197 // language[-country] (e.g., en-US) where the language is the 2 letter code from |
201 // ISO-639. | 198 // ISO-639. |
202 std::wstring GetSystemLocale() { | 199 std::string GetSystemLocale() { |
203 std::string language, region; | 200 std::string language, region; |
204 GetLanguageAndRegionFromOS(&language, ®ion); | 201 GetLanguageAndRegionFromOS(&language, ®ion); |
205 std::string ret; | 202 std::string ret; |
206 if (!language.empty()) | 203 if (!language.empty()) |
207 ret.append(language); | 204 ret.append(language); |
208 if (!region.empty()) { | 205 if (!region.empty()) { |
209 ret.append("-"); | 206 ret.append("-"); |
210 ret.append(region); | 207 ret.append(region); |
211 } | 208 } |
212 return ASCIIToWide(ret); | 209 return ret; |
213 } | 210 } |
214 | 211 |
215 } // namespace | 212 } // namespace |
216 | 213 |
217 namespace l10n_util { | 214 namespace l10n_util { |
218 | 215 |
219 // Represents the locale-specific text direction. | 216 // Represents the locale-specific text direction. |
220 static TextDirection g_text_direction = UNKNOWN_DIRECTION; | 217 static TextDirection g_text_direction = UNKNOWN_DIRECTION; |
221 | 218 |
222 std::wstring GetApplicationLocale(const std::wstring& pref_locale) { | 219 std::string GetApplicationLocale(const std::wstring& pref_locale) { |
223 #if defined(OS_MACOSX) | 220 #if defined(OS_MACOSX) |
224 // On the mac, we don't want to test preferences or ICU for the language, | 221 // On the mac, we don't want to test preferences or ICU for the language, |
225 // we want to use whatever Cocoa is using when it loaded the main nib file. | 222 // we want to use whatever Cocoa is using when it loaded the main nib file. |
226 // It handles all the mapping and fallbacks for us, we just need to ask | 223 // It handles all the mapping and fallbacks for us, we just need to ask |
227 // Cocoa. | 224 // Cocoa. |
228 // TODO(pinkerton): break this out into a .mm and ask Cocoa. | 225 // TODO(pinkerton): break this out into a .mm and ask Cocoa. |
229 return L"en"; | 226 return "en"; |
230 #else | 227 #else |
231 FilePath locale_path; | 228 FilePath locale_path; |
232 PathService::Get(app::DIR_LOCALES, &locale_path); | 229 PathService::Get(app::DIR_LOCALES, &locale_path); |
233 std::wstring resolved_locale; | 230 std::string resolved_locale; |
234 | 231 |
235 // First, check to see if there's a --lang flag. | 232 // First, check to see if there's a --lang flag. |
236 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 233 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
237 const std::wstring& lang_arg = | 234 const std::string& lang_arg = WideToASCII( |
238 parsed_command_line.GetSwitchValue(switches::kLang); | 235 parsed_command_line.GetSwitchValue(switches::kLang)); |
239 if (!lang_arg.empty()) { | 236 if (!lang_arg.empty()) { |
240 if (CheckAndResolveLocale(lang_arg, locale_path.ToWStringHack(), | 237 if (CheckAndResolveLocale(lang_arg, locale_path, &resolved_locale)) |
241 &resolved_locale)) | |
242 return resolved_locale; | 238 return resolved_locale; |
243 } | 239 } |
244 | 240 |
245 // Second, try user prefs. | 241 // Second, try user prefs. |
246 if (!pref_locale.empty()) { | 242 if (!pref_locale.empty()) { |
247 if (CheckAndResolveLocale(pref_locale, locale_path.ToWStringHack(), | 243 if (CheckAndResolveLocale(WideToASCII(pref_locale), |
248 &resolved_locale)) | 244 locale_path, &resolved_locale)) |
249 return resolved_locale; | 245 return resolved_locale; |
250 } | 246 } |
251 | 247 |
252 // Next, try the system locale. | 248 // Next, try the system locale. |
253 const std::wstring system_locale = GetSystemLocale(); | 249 const std::string system_locale = GetSystemLocale(); |
254 if (CheckAndResolveLocale(system_locale, locale_path.ToWStringHack(), | 250 if (CheckAndResolveLocale(system_locale, locale_path, &resolved_locale)) |
255 &resolved_locale)) | |
256 return resolved_locale; | 251 return resolved_locale; |
257 | 252 |
258 // Fallback on en-US. | 253 // Fallback on en-US. |
259 const std::wstring fallback_locale(L"en-US"); | 254 const std::string fallback_locale("en-US"); |
260 if (IsLocaleAvailable(fallback_locale, locale_path.ToWStringHack())) | 255 if (IsLocaleAvailable(fallback_locale, locale_path)) |
261 return fallback_locale; | 256 return fallback_locale; |
262 | 257 |
263 // No locale data file was found; we shouldn't get here. | 258 // No locale data file was found; we shouldn't get here. |
264 NOTREACHED(); | 259 NOTREACHED(); |
265 | 260 |
266 return std::wstring(); | 261 return std::string(); |
267 #endif | 262 #endif |
268 } | 263 } |
269 | 264 |
270 std::wstring GetLocalName(const std::string& locale_code_str, | 265 string16 GetDisplayNameForLocale(const std::string& locale_code, |
271 const std::wstring& app_locale_wstr, | 266 const std::string& display_locale, |
272 bool is_for_ui) { | 267 bool is_for_ui) { |
273 const std::string app_locale = WideToASCII(app_locale_wstr); | |
274 const char* locale_code = locale_code_str.c_str(); | |
275 UErrorCode error = U_ZERO_ERROR; | 268 UErrorCode error = U_ZERO_ERROR; |
276 const int buffer_size = 1024; | 269 const int buffer_size = 1024; |
277 | 270 |
278 #if defined(WCHAR_T_IS_UTF32) | 271 string16 display_name; |
279 string16 name_local_utf16; | 272 int actual_size = uloc_getDisplayName(locale_code.c_str(), |
280 int actual_size = uloc_getDisplayName(locale_code, app_locale.c_str(), | 273 display_locale.c_str(), |
281 WriteInto(&name_local_utf16, buffer_size + 1), buffer_size, &error); | 274 WriteInto(&display_name, buffer_size + 1), buffer_size, &error); |
282 std::wstring name_local = UTF16ToWide(name_local_utf16); | |
283 #else | |
284 std::wstring name_local; | |
285 int actual_size = uloc_getDisplayName(locale_code, app_locale.c_str(), | |
286 WriteInto(&name_local, buffer_size + 1), buffer_size, &error); | |
287 #endif | |
288 DCHECK(U_SUCCESS(error)); | 275 DCHECK(U_SUCCESS(error)); |
289 name_local.resize(actual_size); | 276 display_name.resize(actual_size); |
290 // Add an RTL mark so parentheses are properly placed. | 277 // Add an RTL mark so parentheses are properly placed. |
291 if (is_for_ui && GetTextDirection() == RIGHT_TO_LEFT) { | 278 if (is_for_ui && GetTextDirection() == RIGHT_TO_LEFT) { |
292 name_local.push_back(static_cast<wchar_t>(kRightToLeftMark)); | 279 display_name.push_back(static_cast<char16>(kRightToLeftMark)); |
293 } | 280 } |
294 return name_local; | 281 return display_name; |
295 } | 282 } |
296 | 283 |
297 std::wstring GetString(int message_id) { | 284 std::wstring GetString(int message_id) { |
298 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 285 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
299 return UTF16ToWide(rb.GetLocalizedString(message_id)); | 286 return UTF16ToWide(rb.GetLocalizedString(message_id)); |
300 } | 287 } |
301 | 288 |
302 std::string GetStringUTF8(int message_id) { | 289 std::string GetStringUTF8(int message_id) { |
303 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 290 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
304 return UTF16ToUTF8(rb.GetLocalizedString(message_id)); | 291 return UTF16ToUTF8(rb.GetLocalizedString(message_id)); |
(...skipping 15 matching lines...) Expand all Loading... |
320 std::vector<string16> subst; | 307 std::vector<string16> subst; |
321 subst.push_back(a); | 308 subst.push_back(a); |
322 subst.push_back(b); | 309 subst.push_back(b); |
323 subst.push_back(c); | 310 subst.push_back(c); |
324 subst.push_back(d); | 311 subst.push_back(d); |
325 string16 formatted = ReplaceStringPlaceholders(format_string, subst, | 312 string16 formatted = ReplaceStringPlaceholders(format_string, subst, |
326 offsets); | 313 offsets); |
327 return formatted; | 314 return formatted; |
328 } | 315 } |
329 | 316 |
| 317 #if !defined(WCHAR_T_IS_UTF16) |
330 std::wstring GetStringF(int message_id, const std::wstring& a) { | 318 std::wstring GetStringF(int message_id, const std::wstring& a) { |
331 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), string16(), | 319 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), string16(), |
332 string16(), string16(), NULL)); | 320 string16(), string16(), NULL)); |
333 } | 321 } |
334 | 322 |
335 std::wstring GetStringF(int message_id, | 323 std::wstring GetStringF(int message_id, |
336 const std::wstring& a, | 324 const std::wstring& a, |
337 const std::wstring& b) { | 325 const std::wstring& b) { |
338 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), WideToUTF16(b), | 326 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), WideToUTF16(b), |
339 string16(), string16(), NULL)); | 327 string16(), string16(), NULL)); |
340 } | 328 } |
341 | 329 |
342 std::wstring GetStringF(int message_id, | 330 std::wstring GetStringF(int message_id, |
343 const std::wstring& a, | 331 const std::wstring& a, |
344 const std::wstring& b, | 332 const std::wstring& b, |
345 const std::wstring& c) { | 333 const std::wstring& c) { |
346 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), WideToUTF16(b), | 334 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), WideToUTF16(b), |
347 WideToUTF16(c), string16(), NULL)); | 335 WideToUTF16(c), string16(), NULL)); |
348 } | 336 } |
349 | 337 |
350 std::wstring GetStringF(int message_id, | 338 std::wstring GetStringF(int message_id, |
351 const std::wstring& a, | 339 const std::wstring& a, |
352 const std::wstring& b, | 340 const std::wstring& b, |
353 const std::wstring& c, | 341 const std::wstring& c, |
354 const std::wstring& d) { | 342 const std::wstring& d) { |
355 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), WideToUTF16(b), | 343 return UTF16ToWide(GetStringF(message_id, WideToUTF16(a), WideToUTF16(b), |
356 WideToUTF16(c), WideToUTF16(d), NULL)); | 344 WideToUTF16(c), WideToUTF16(d), NULL)); |
357 } | 345 } |
| 346 #endif |
358 | 347 |
359 std::string GetStringFUTF8(int message_id, | 348 std::string GetStringFUTF8(int message_id, |
360 const string16& a) { | 349 const string16& a) { |
361 return UTF16ToUTF8(GetStringF(message_id, a, string16(), string16(), | 350 return UTF16ToUTF8(GetStringF(message_id, a, string16(), string16(), |
362 string16(), NULL)); | 351 string16(), NULL)); |
363 } | 352 } |
364 | 353 |
365 std::string GetStringFUTF8(int message_id, | 354 std::string GetStringFUTF8(int message_id, |
366 const string16& a, | 355 const string16& a, |
367 const string16& b) { | 356 const string16& b) { |
368 return UTF16ToUTF8(GetStringF(message_id, a, b, string16(), string16(), | 357 return UTF16ToUTF8(GetStringF(message_id, a, b, string16(), string16(), |
369 NULL)); | 358 NULL)); |
370 } | 359 } |
371 | 360 |
372 std::string GetStringFUTF8(int message_id, | 361 std::string GetStringFUTF8(int message_id, |
373 const string16& a, | 362 const string16& a, |
374 const string16& b, | 363 const string16& b, |
375 const string16& c) { | 364 const string16& c) { |
376 return UTF16ToUTF8(GetStringF(message_id, a, b, c, string16(), NULL)); | 365 return UTF16ToUTF8(GetStringF(message_id, a, b, c, string16(), NULL)); |
377 } | 366 } |
378 | 367 |
379 std::string GetStringFUTF8(int message_id, | 368 std::string GetStringFUTF8(int message_id, |
380 const string16& a, | 369 const string16& a, |
381 const string16& b, | 370 const string16& b, |
382 const string16& c, | 371 const string16& c, |
383 const string16& d) { | 372 const string16& d) { |
384 return UTF16ToUTF8(GetStringF(message_id, a, b, c, d, NULL)); | 373 return UTF16ToUTF8(GetStringF(message_id, a, b, c, d, NULL)); |
385 } | 374 } |
386 | 375 |
| 376 string16 GetStringFUTF16(int message_id, |
| 377 const string16& a) { |
| 378 return GetStringF(message_id, a, string16(), string16(), string16(), NULL); |
| 379 } |
| 380 |
| 381 string16 GetStringFUTF16(int message_id, |
| 382 const string16& a, |
| 383 const string16& b) { |
| 384 return GetStringF(message_id, a, b, string16(), string16(), NULL); |
| 385 } |
| 386 |
| 387 string16 GetStringFUTF16(int message_id, |
| 388 const string16& a, |
| 389 const string16& b, |
| 390 const string16& c) { |
| 391 return GetStringF(message_id, a, b, c, string16(), NULL); |
| 392 } |
| 393 |
| 394 string16 GetStringFUTF16(int message_id, |
| 395 const string16& a, |
| 396 const string16& b, |
| 397 const string16& c, |
| 398 const string16& d) { |
| 399 return GetStringF(message_id, a, b, c, d, NULL); |
| 400 } |
| 401 |
387 std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset) { | 402 std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset) { |
388 DCHECK(offset); | 403 DCHECK(offset); |
389 std::vector<size_t> offsets; | 404 std::vector<size_t> offsets; |
390 string16 result = GetStringF(message_id, WideToUTF16(a), string16(), | 405 string16 result = GetStringF(message_id, WideToUTF16(a), string16(), |
391 string16(), string16(), &offsets); | 406 string16(), string16(), &offsets); |
392 DCHECK(offsets.size() == 1); | 407 DCHECK(offsets.size() == 1); |
393 *offset = offsets[0]; | 408 *offset = offsets[0]; |
394 return UTF16ToWide(result); | 409 return UTF16ToWide(result); |
395 } | 410 } |
396 | 411 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 template <> | 686 template <> |
672 bool StringComparator<std::wstring>::operator()(const std::wstring& lhs, | 687 bool StringComparator<std::wstring>::operator()(const std::wstring& lhs, |
673 const std::wstring& rhs) { | 688 const std::wstring& rhs) { |
674 // If we can not get collator instance for specified locale, just do simple | 689 // If we can not get collator instance for specified locale, just do simple |
675 // string compare. | 690 // string compare. |
676 if (!collator_) | 691 if (!collator_) |
677 return lhs < rhs; | 692 return lhs < rhs; |
678 return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS; | 693 return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS; |
679 }; | 694 }; |
680 | 695 |
681 void SortStrings(const std::wstring& locale, | 696 void SortStrings(const std::string& locale, |
682 std::vector<std::wstring>* strings) { | 697 std::vector<std::wstring>* strings) { |
683 SortVectorWithStringKey(locale, strings, false); | 698 SortVectorWithStringKey(locale, strings, false); |
684 } | 699 } |
685 | 700 |
686 const std::vector<std::string>& GetAvailableLocales() { | 701 const std::vector<std::string>& GetAvailableLocales() { |
687 static std::vector<std::string> locales; | 702 static std::vector<std::string> locales; |
688 if (locales.empty()) { | 703 if (locales.empty()) { |
689 int num_locales = uloc_countAvailable(); | 704 int num_locales = uloc_countAvailable(); |
690 for (int i = 0; i < num_locales; ++i) { | 705 for (int i = 0; i < num_locales; ++i) { |
691 std::string locale_name = uloc_getAvailable(i); | 706 std::string locale_name = uloc_getAvailable(i); |
692 // Filter out the names that have aliases. | 707 // Filter out the names that have aliases. |
693 if (IsDuplicateName(locale_name)) | 708 if (IsDuplicateName(locale_name)) |
694 continue; | 709 continue; |
695 if (!IsLocaleSupportedByOS(ASCIIToWide(locale_name))) | 710 if (!IsLocaleSupportedByOS(locale_name)) |
696 continue; | 711 continue; |
697 // Normalize underscores to hyphens because that's what our locale files | 712 // Normalize underscores to hyphens because that's what our locale files |
698 // use. | 713 // use. |
699 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); | 714 std::replace(locale_name.begin(), locale_name.end(), '_', '-'); |
700 | 715 |
701 // Map the Chinese locale names over to zh-CN and zh-TW. | 716 // Map the Chinese locale names over to zh-CN and zh-TW. |
702 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) { | 717 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) { |
703 locale_name = "zh-CN"; | 718 locale_name = "zh-CN"; |
704 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) { | 719 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) { |
705 locale_name = "zh-TW"; | 720 locale_name = "zh-TW"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } | 771 } |
757 | 772 |
758 void BiDiLineIterator::GetLogicalRun(int start, | 773 void BiDiLineIterator::GetLogicalRun(int start, |
759 int* end, | 774 int* end, |
760 UBiDiLevel* level) { | 775 UBiDiLevel* level) { |
761 DCHECK(bidi_ != NULL); | 776 DCHECK(bidi_ != NULL); |
762 ubidi_getLogicalRun(bidi_, start, end, level); | 777 ubidi_getLogicalRun(bidi_, start, end, level); |
763 } | 778 } |
764 | 779 |
765 } | 780 } |
OLD | NEW |