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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 return !base::IsStringASCII(display_name) || | 508 return !base::IsStringASCII(display_name) || |
509 base::UTF16ToASCII(display_name) != locale; | 509 base::UTF16ToASCII(display_name) != locale; |
510 } | 510 } |
511 | 511 |
512 base::string16 GetDisplayNameForLocale(const std::string& locale, | 512 base::string16 GetDisplayNameForLocale(const std::string& locale, |
513 const std::string& display_locale, | 513 const std::string& display_locale, |
514 bool is_for_ui) { | 514 bool is_for_ui) { |
515 std::string locale_code = locale; | 515 std::string locale_code = locale; |
516 // Internally, we use the language code of zh-CN and zh-TW, but we want the | 516 // Internally, we use the language code of zh-CN and zh-TW, but we want the |
517 // display names to be Chinese (Simplified) and Chinese (Traditional) instead | 517 // display names to be Chinese (Simplified) and Chinese (Traditional) instead |
518 // of Chinese (China) and Chinese (Taiwan). | 518 // of Chinese (China) and Chinese (Taiwan). To do that, we pass zh-Hans |
519 // Translate uses "tl" (Tagalog) to mean "fil" (Filipino) until Google | 519 // and zh-Hant to ICU. Even with this mapping, we'd get |
520 // translate is changed to understand "fil". Make "tl" alias to "fil". | 520 // 'Chinese (Simplified Han)' and 'Chinese (Traditional Han)' in English and |
| 521 // even longer results in other languages. Arguably, they're better than |
| 522 // the current results : Chinese (China) / Chinese (Taiwan). |
| 523 // TODO(jungshik): Do one of the following: |
| 524 // 1. Special-case Chinese by getting the custom-translation for them |
| 525 // 2. Recycle IDS_ENCODING_{SIMP,TRAD}_CHINESE. |
| 526 // 3. Get translations for two directly from the ICU resouce bundle |
| 527 // because they're not accessible with other any API. |
| 528 // 4. Patch ICU to special-case zh-Hans/zh-Hant for us. |
| 529 // #1 and #2 wouldn't work if display_locale != current UI locale although |
| 530 // we can think of additional hack to work around the problem. |
| 531 // #3 can be potentially expensive. |
521 if (locale_code == "zh-CN") | 532 if (locale_code == "zh-CN") |
522 locale_code = "zh-Hans"; | 533 locale_code = "zh-Hans"; |
523 else if (locale_code == "zh-TW") | 534 else if (locale_code == "zh-TW") |
524 locale_code = "zh-Hant"; | 535 locale_code = "zh-Hant"; |
525 else if (locale_code == "tl") | |
526 locale_code = "fil"; | |
527 | 536 |
528 base::string16 display_name; | 537 base::string16 display_name; |
529 #if defined(OS_ANDROID) | 538 #if defined(OS_ANDROID) |
530 // Use Java API to get locale display name so that we can remove most of | 539 // Use Java API to get locale display name so that we can remove most of |
531 // the lang data from icu data to reduce binary size, except for zh-Hans and | 540 // the lang data from icu data to reduce binary size, except for zh-Hans and |
532 // zh-Hant because the current Android Java API doesn't support scripts. | 541 // zh-Hant because the current Android Java API doesn't support scripts. |
533 // TODO(wangxianzhu): remove the special handling of zh-Hans and zh-Hant once | 542 // TODO(wangxianzhu): remove the special handling of zh-Hans and zh-Hant once |
534 // Android Java API supports scripts. | 543 // Android Java API supports scripts. |
535 if (!StartsWithASCII(locale_code, "zh-Han", true)) { | 544 if (!StartsWithASCII(locale_code, "zh-Han", true)) { |
536 display_name = GetDisplayNameForLocale(locale_code, display_locale); | 545 display_name = GetDisplayNameForLocale(locale_code, display_locale); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 } | 880 } |
872 | 881 |
873 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { | 882 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { |
874 int width = 0; | 883 int width = 0; |
875 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); | 884 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); |
876 DCHECK_GT(width, 0); | 885 DCHECK_GT(width, 0); |
877 return width; | 886 return width; |
878 } | 887 } |
879 | 888 |
880 } // namespace l10n_util | 889 } // namespace l10n_util |
OLD | NEW |