OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/l10n/l10n_util.h" | 5 #include "ui/base/l10n/l10n_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <string> | 10 #include <string> |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 std::string::size_type variant_pos = locale.find('@'); | 262 std::string::size_type variant_pos = locale.find('@'); |
263 if (variant_pos != std::string::npos) | 263 if (variant_pos != std::string::npos) |
264 return false; | 264 return false; |
265 | 265 |
266 // If the locale matches language but not country, use that instead. | 266 // If the locale matches language but not country, use that instead. |
267 // TODO(jungshik) : Nothing is done about languages that Chrome | 267 // TODO(jungshik) : Nothing is done about languages that Chrome |
268 // does not support but available on Windows. We fall | 268 // does not support but available on Windows. We fall |
269 // back to en-US in GetApplicationLocale so that it's a not critical, | 269 // back to en-US in GetApplicationLocale so that it's a not critical, |
270 // but we can do better. | 270 // but we can do better. |
271 std::string::size_type hyphen_pos = locale.find('-'); | 271 std::string::size_type hyphen_pos = locale.find('-'); |
| 272 std::string lang(locale, 0, hyphen_pos); |
272 if (hyphen_pos != std::string::npos && hyphen_pos > 0) { | 273 if (hyphen_pos != std::string::npos && hyphen_pos > 0) { |
273 std::string lang(locale, 0, hyphen_pos); | |
274 std::string region(locale, hyphen_pos + 1); | 274 std::string region(locale, hyphen_pos + 1); |
275 std::string tmp_locale(lang); | 275 std::string tmp_locale(lang); |
276 // Map es-RR other than es-ES to es-419 (Chrome's Latin American | 276 // Map es-RR other than es-ES to es-419 (Chrome's Latin American |
277 // Spanish locale). | 277 // Spanish locale). |
278 if (LowerCaseEqualsASCII(lang, "es") && | 278 if (LowerCaseEqualsASCII(lang, "es") && |
279 !LowerCaseEqualsASCII(region, "es")) { | 279 !LowerCaseEqualsASCII(region, "es")) { |
280 tmp_locale.append("-419"); | 280 tmp_locale.append("-419"); |
281 } else if (LowerCaseEqualsASCII(lang, "zh")) { | 281 } else if (LowerCaseEqualsASCII(lang, "zh")) { |
282 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. | 282 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. |
283 if (LowerCaseEqualsASCII(region, "hk") || | 283 if (LowerCaseEqualsASCII(region, "hk") || |
(...skipping 15 matching lines...) Expand all Loading... |
299 } else { | 299 } else { |
300 tmp_locale.append("-US"); | 300 tmp_locale.append("-US"); |
301 } | 301 } |
302 } | 302 } |
303 if (IsLocaleAvailable(tmp_locale)) { | 303 if (IsLocaleAvailable(tmp_locale)) { |
304 resolved_locale->swap(tmp_locale); | 304 resolved_locale->swap(tmp_locale); |
305 return true; | 305 return true; |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 // Google updater uses no, iw and en for our nb, he, and en-US. | 309 // Google updater uses no, iw and en for our nb, he, and en-US, and |
310 // We need to map them to our codes. | 310 // Android uses iw-*, in-*, and ji-*. We need to map them to our codes. |
311 struct { | 311 struct { |
312 const char* source; | 312 const char* source; |
313 const char* dest; | 313 const char* dest; |
314 } alias_map[] = { | 314 } alias_map[] = { |
315 {"no", "nb"}, | 315 {"no", "nb"}, |
316 {"tl", "fil"}, | 316 {"tl", "fil"}, |
317 {"iw", "he"}, | 317 {"iw", "he"}, |
318 {"en", "en-US"}, | 318 {"en", "en-US"}, |
| 319 {"in", "id"}, |
| 320 {"ji", "yi"}, |
319 }; | 321 }; |
320 | 322 |
321 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) { | 323 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) { |
322 if (LowerCaseEqualsASCII(locale, alias_map[i].source)) { | 324 if (LowerCaseEqualsASCII(lang, alias_map[i].source)) { |
323 std::string tmp_locale(alias_map[i].dest); | 325 std::string tmp_locale(alias_map[i].dest); |
324 if (IsLocaleAvailable(tmp_locale)) { | 326 if (IsLocaleAvailable(tmp_locale)) { |
325 resolved_locale->swap(tmp_locale); | 327 resolved_locale->swap(tmp_locale); |
326 return true; | 328 return true; |
327 } | 329 } |
328 } | 330 } |
329 } | 331 } |
330 | 332 |
331 return false; | 333 return false; |
332 } | 334 } |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 844 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { |
843 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) | 845 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) |
844 // TODO(jungshik) : Put them at the of the list with language codes | 846 // TODO(jungshik) : Put them at the of the list with language codes |
845 // enclosed by brackets instead of skipping. | 847 // enclosed by brackets instead of skipping. |
846 continue; | 848 continue; |
847 locale_codes->push_back(kAcceptLanguageList[i]); | 849 locale_codes->push_back(kAcceptLanguageList[i]); |
848 } | 850 } |
849 } | 851 } |
850 | 852 |
851 } // namespace l10n_util | 853 } // namespace l10n_util |
OLD | NEW |