OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
8 #include <glib/gutils.h> | 8 #include <glib/gutils.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 return file_util::PathExists(test_path); | 252 return file_util::PathExists(test_path); |
253 } | 253 } |
254 | 254 |
255 bool CheckAndResolveLocale(const std::string& locale, | 255 bool CheckAndResolveLocale(const std::string& locale, |
256 const FilePath& locale_path, | 256 const FilePath& locale_path, |
257 std::string* resolved_locale) { | 257 std::string* resolved_locale) { |
258 if (IsLocaleAvailable(locale, locale_path)) { | 258 if (IsLocaleAvailable(locale, locale_path)) { |
259 *resolved_locale = locale; | 259 *resolved_locale = locale; |
260 return true; | 260 return true; |
261 } | 261 } |
262 | |
263 // If there's a variant, skip over it so we can try without the language | |
264 // code. For example, ca_ES@valencia should cause us to try ca@valencia | |
jungshik at Google
2011/05/31 09:23:52
nit: 'without the language code' => 'without the r
| |
265 // before ca. | |
266 std::string::size_type variant_pos = locale.find('@'); | |
267 if (variant_pos != std::string::npos) | |
268 return false; | |
James Su
2011/05/30 02:00:49
If I understand correctly, this fix implies that t
| |
269 | |
262 // If the locale matches language but not country, use that instead. | 270 // If the locale matches language but not country, use that instead. |
263 // TODO(jungshik) : Nothing is done about languages that Chrome | 271 // TODO(jungshik) : Nothing is done about languages that Chrome |
264 // does not support but available on Windows. We fall | 272 // does not support but available on Windows. We fall |
265 // back to en-US in GetApplicationLocale so that it's a not critical, | 273 // back to en-US in GetApplicationLocale so that it's a not critical, |
266 // but we can do better. | 274 // but we can do better. |
267 std::string::size_type hyphen_pos = locale.find('-'); | 275 std::string::size_type hyphen_pos = locale.find('-'); |
268 if (hyphen_pos != std::string::npos && hyphen_pos > 0) { | 276 if (hyphen_pos != std::string::npos && hyphen_pos > 0) { |
269 std::string lang(locale, 0, hyphen_pos); | 277 std::string lang(locale, 0, hyphen_pos); |
270 std::string region(locale, hyphen_pos + 1); | 278 std::string region(locale, hyphen_pos + 1); |
271 std::string tmp_locale(lang); | 279 std::string tmp_locale(lang); |
272 // Map es-RR other than es-ES to es-419 (Chrome's Latin American | 280 // Map es-RR other than es-ES to es-419 (Chrome's Latin American |
273 // Spanish locale). | 281 // Spanish locale). |
274 if (LowerCaseEqualsASCII(lang, "es") && !LowerCaseEqualsASCII(region, "es")) | 282 if (LowerCaseEqualsASCII(lang, "es") && !LowerCaseEqualsASCII(region, "es")) |
275 tmp_locale.append("-419"); | 283 tmp_locale.append("-419"); |
276 else if (LowerCaseEqualsASCII(lang, "zh")) { | 284 else if (LowerCaseEqualsASCII(lang, "zh")) { |
277 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. | 285 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN. |
278 if (LowerCaseEqualsASCII(region, "hk") || | 286 if (LowerCaseEqualsASCII(region, "hk") || |
279 LowerCaseEqualsASCII(region, "mo")) { // Macao | 287 LowerCaseEqualsASCII(region, "mo")) { // Macao |
280 tmp_locale.append("-TW"); | 288 tmp_locale.append("-TW"); |
281 } else { | 289 } else { |
282 tmp_locale.append("-CN"); | 290 tmp_locale.append("-CN"); |
283 } | 291 } |
284 } | 292 } |
285 if (IsLocaleAvailable(tmp_locale, locale_path)) { | 293 if (IsLocaleAvailable(tmp_locale, locale_path)) { |
286 resolved_locale->swap(tmp_locale); | 294 resolved_locale->swap(tmp_locale); |
287 return true; | 295 return true; |
288 } | 296 } |
289 } | 297 } |
290 | 298 |
291 // Google updater uses no, iw and en for our nb, he, and en-US. | 299 // Google updater uses no, iw and en for our nb, he, and en-US. |
292 // We need to map them to our codes. | 300 // We need to map them to our codes. |
293 struct { | 301 struct { |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
851 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 859 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { |
852 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) | 860 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) |
853 // TODO(jungshik) : Put them at the of the list with language codes | 861 // TODO(jungshik) : Put them at the of the list with language codes |
854 // enclosed by brackets instead of skipping. | 862 // enclosed by brackets instead of skipping. |
855 continue; | 863 continue; |
856 locale_codes->push_back(kAcceptLanguageList[i]); | 864 locale_codes->push_back(kAcceptLanguageList[i]); |
857 } | 865 } |
858 } | 866 } |
859 | 867 |
860 } // namespace l10n_util | 868 } // namespace l10n_util |
OLD | NEW |