| 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). To do that, we pass zh-Hans | 518 // of Chinese (China) and Chinese (Taiwan). |
| 519 // and zh-Hant to ICU. Even with this mapping, we'd get | 519 // Translate uses "tl" (Tagalog) to mean "fil" (Filipino) until Google |
| 520 // 'Chinese (Simplified Han)' and 'Chinese (Traditional Han)' in English and | 520 // translate is changed to understand "fil". Make "tl" alias to "fil". |
| 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. | |
| 532 if (locale_code == "zh-CN") | 521 if (locale_code == "zh-CN") |
| 533 locale_code = "zh-Hans"; | 522 locale_code = "zh-Hans"; |
| 534 else if (locale_code == "zh-TW") | 523 else if (locale_code == "zh-TW") |
| 535 locale_code = "zh-Hant"; | 524 locale_code = "zh-Hant"; |
| 525 else if (locale_code == "tl") |
| 526 locale_code = "fil"; |
| 536 | 527 |
| 537 base::string16 display_name; | 528 base::string16 display_name; |
| 538 #if defined(OS_ANDROID) | 529 #if defined(OS_ANDROID) |
| 539 // Use Java API to get locale display name so that we can remove most of | 530 // Use Java API to get locale display name so that we can remove most of |
| 540 // the lang data from icu data to reduce binary size, except for zh-Hans and | 531 // the lang data from icu data to reduce binary size, except for zh-Hans and |
| 541 // zh-Hant because the current Android Java API doesn't support scripts. | 532 // zh-Hant because the current Android Java API doesn't support scripts. |
| 542 // TODO(wangxianzhu): remove the special handling of zh-Hans and zh-Hant once | 533 // TODO(wangxianzhu): remove the special handling of zh-Hans and zh-Hant once |
| 543 // Android Java API supports scripts. | 534 // Android Java API supports scripts. |
| 544 if (!StartsWithASCII(locale_code, "zh-Han", true)) { | 535 if (!StartsWithASCII(locale_code, "zh-Han", true)) { |
| 545 display_name = GetDisplayNameForLocale(locale_code, display_locale); | 536 display_name = GetDisplayNameForLocale(locale_code, display_locale); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 } | 871 } |
| 881 | 872 |
| 882 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { | 873 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { |
| 883 int width = 0; | 874 int width = 0; |
| 884 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); | 875 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); |
| 885 DCHECK_GT(width, 0); | 876 DCHECK_GT(width, 0); |
| 886 return width; | 877 return width; |
| 887 } | 878 } |
| 888 | 879 |
| 889 } // namespace l10n_util | 880 } // namespace l10n_util |
| OLD | NEW |