| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // See crbug.com/230432: CHECK failure in GetUserDataDir(). | 246 // See crbug.com/230432: CHECK failure in GetUserDataDir(). |
| 247 return ResourceBundle::GetSharedInstance().LocaleDataPakExists(locale); | 247 return ResourceBundle::GetSharedInstance().LocaleDataPakExists(locale); |
| 248 } | 248 } |
| 249 #endif | 249 #endif |
| 250 | 250 |
| 251 // On Linux, the text layout engine Pango determines paragraph directionality | 251 // On Linux, the text layout engine Pango determines paragraph directionality |
| 252 // by looking at the first strongly-directional character in the text. This | 252 // by looking at the first strongly-directional character in the text. This |
| 253 // means text such as "Google Chrome foo bar..." will be layed out LTR even | 253 // means text such as "Google Chrome foo bar..." will be layed out LTR even |
| 254 // if "foo bar" is RTL. So this function prepends the necessary RLM in such | 254 // if "foo bar" is RTL. So this function prepends the necessary RLM in such |
| 255 // cases. | 255 // cases. |
| 256 void AdjustParagraphDirectionality(string16* paragraph) { | 256 void AdjustParagraphDirectionality(base::string16* paragraph) { |
| 257 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) | 257 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 258 if (base::i18n::IsRTL() && | 258 if (base::i18n::IsRTL() && |
| 259 base::i18n::StringContainsStrongRTLChars(*paragraph)) { | 259 base::i18n::StringContainsStrongRTLChars(*paragraph)) { |
| 260 paragraph->insert(0, 1, static_cast<char16>(base::i18n::kRightToLeftMark)); | 260 paragraph->insert(0, 1, |
| 261 static_cast<base::char16>(base::i18n::kRightToLeftMark)); |
| 261 } | 262 } |
| 262 #endif | 263 #endif |
| 263 } | 264 } |
| 264 | 265 |
| 265 #if defined(OS_WIN) | 266 #if defined(OS_WIN) |
| 266 std::string GetCanonicalLocale(const std::string& locale) { | 267 std::string GetCanonicalLocale(const std::string& locale) { |
| 267 return base::i18n::GetCanonicalLocale(locale.c_str()); | 268 return base::i18n::GetCanonicalLocale(locale.c_str()); |
| 268 } | 269 } |
| 269 #endif | 270 #endif |
| 270 | 271 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 return fallback_locale; | 492 return fallback_locale; |
| 492 } | 493 } |
| 493 | 494 |
| 494 return std::string(); | 495 return std::string(); |
| 495 | 496 |
| 496 #endif | 497 #endif |
| 497 } | 498 } |
| 498 | 499 |
| 499 bool IsLocaleNameTranslated(const char* locale, | 500 bool IsLocaleNameTranslated(const char* locale, |
| 500 const std::string& display_locale) { | 501 const std::string& display_locale) { |
| 501 string16 display_name = | 502 base::string16 display_name = |
| 502 l10n_util::GetDisplayNameForLocale(locale, display_locale, false); | 503 l10n_util::GetDisplayNameForLocale(locale, display_locale, false); |
| 503 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not | 504 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not |
| 504 // uloc_getDisplayName returns the actual translation or the default | 505 // uloc_getDisplayName returns the actual translation or the default |
| 505 // value (locale code), we have to rely on this hack to tell whether | 506 // value (locale code), we have to rely on this hack to tell whether |
| 506 // the translation is available or not. If ICU doesn't have a translated | 507 // the translation is available or not. If ICU doesn't have a translated |
| 507 // name for this locale, GetDisplayNameForLocale will just return the | 508 // name for this locale, GetDisplayNameForLocale will just return the |
| 508 // locale code. | 509 // locale code. |
| 509 return !IsStringASCII(display_name) || UTF16ToASCII(display_name) != locale; | 510 return !IsStringASCII(display_name) || UTF16ToASCII(display_name) != locale; |
| 510 } | 511 } |
| 511 | 512 |
| 512 string16 GetDisplayNameForLocale(const std::string& locale, | 513 base::string16 GetDisplayNameForLocale(const std::string& locale, |
| 513 const std::string& display_locale, | 514 const std::string& display_locale, |
| 514 bool is_for_ui) { | 515 bool is_for_ui) { |
| 515 std::string locale_code = locale; | 516 std::string locale_code = locale; |
| 516 // Internally, we use the language code of zh-CN and zh-TW, but we want the | 517 // 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 | 518 // display names to be Chinese (Simplified) and Chinese (Traditional) instead |
| 518 // of Chinese (China) and Chinese (Taiwan). To do that, we pass zh-Hans | 519 // of Chinese (China) and Chinese (Taiwan). To do that, we pass zh-Hans |
| 519 // and zh-Hant to ICU. Even with this mapping, we'd get | 520 // and zh-Hant to ICU. Even with this mapping, we'd get |
| 520 // 'Chinese (Simplified Han)' and 'Chinese (Traditional Han)' in English and | 521 // 'Chinese (Simplified Han)' and 'Chinese (Traditional Han)' in English and |
| 521 // even longer results in other languages. Arguably, they're better than | 522 // even longer results in other languages. Arguably, they're better than |
| 522 // the current results : Chinese (China) / Chinese (Taiwan). | 523 // the current results : Chinese (China) / Chinese (Taiwan). |
| 523 // TODO(jungshik): Do one of the following: | 524 // TODO(jungshik): Do one of the following: |
| 524 // 1. Special-case Chinese by getting the custom-translation for them | 525 // 1. Special-case Chinese by getting the custom-translation for them |
| 525 // 2. Recycle IDS_ENCODING_{SIMP,TRAD}_CHINESE. | 526 // 2. Recycle IDS_ENCODING_{SIMP,TRAD}_CHINESE. |
| 526 // 3. Get translations for two directly from the ICU resouce bundle | 527 // 3. Get translations for two directly from the ICU resouce bundle |
| 527 // because they're not accessible with other any API. | 528 // because they're not accessible with other any API. |
| 528 // 4. Patch ICU to special-case zh-Hans/zh-Hant for us. | 529 // 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 // #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 // we can think of additional hack to work around the problem. |
| 531 // #3 can be potentially expensive. | 532 // #3 can be potentially expensive. |
| 532 if (locale_code == "zh-CN") | 533 if (locale_code == "zh-CN") |
| 533 locale_code = "zh-Hans"; | 534 locale_code = "zh-Hans"; |
| 534 else if (locale_code == "zh-TW") | 535 else if (locale_code == "zh-TW") |
| 535 locale_code = "zh-Hant"; | 536 locale_code = "zh-Hant"; |
| 536 | 537 |
| 537 string16 display_name; | 538 base::string16 display_name; |
| 538 #if defined(OS_ANDROID) | 539 #if defined(OS_ANDROID) |
| 539 // Use Java API to get locale display name so that we can remove most of | 540 // 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 | 541 // 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. | 542 // 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 | 543 // TODO(wangxianzhu): remove the special handling of zh-Hans and zh-Hant once |
| 543 // Android Java API supports scripts. | 544 // Android Java API supports scripts. |
| 544 if (!StartsWithASCII(locale_code, "zh-Han", true)) { | 545 if (!StartsWithASCII(locale_code, "zh-Han", true)) { |
| 545 display_name = GetDisplayNameForLocale(locale_code, display_locale); | 546 display_name = GetDisplayNameForLocale(locale_code, display_locale); |
| 546 } else | 547 } else |
| 547 #endif | 548 #endif |
| 548 { | 549 { |
| 549 UErrorCode error = U_ZERO_ERROR; | 550 UErrorCode error = U_ZERO_ERROR; |
| 550 const int kBufferSize = 1024; | 551 const int kBufferSize = 1024; |
| 551 | 552 |
| 552 int actual_size = uloc_getDisplayName( | 553 int actual_size = uloc_getDisplayName( |
| 553 locale_code.c_str(), display_locale.c_str(), | 554 locale_code.c_str(), display_locale.c_str(), |
| 554 WriteInto(&display_name, kBufferSize), kBufferSize - 1, &error); | 555 WriteInto(&display_name, kBufferSize), kBufferSize - 1, &error); |
| 555 DCHECK(U_SUCCESS(error)); | 556 DCHECK(U_SUCCESS(error)); |
| 556 display_name.resize(actual_size); | 557 display_name.resize(actual_size); |
| 557 } | 558 } |
| 558 | 559 |
| 559 // Add directional markup so parentheses are properly placed. | 560 // Add directional markup so parentheses are properly placed. |
| 560 if (is_for_ui && base::i18n::IsRTL()) | 561 if (is_for_ui && base::i18n::IsRTL()) |
| 561 base::i18n::AdjustStringForLocaleDirection(&display_name); | 562 base::i18n::AdjustStringForLocaleDirection(&display_name); |
| 562 return display_name; | 563 return display_name; |
| 563 } | 564 } |
| 564 | 565 |
| 565 string16 GetDisplayNameForCountry(const std::string& country_code, | 566 base::string16 GetDisplayNameForCountry(const std::string& country_code, |
| 566 const std::string& display_locale) { | 567 const std::string& display_locale) { |
| 567 return GetDisplayNameForLocale("_" + country_code, display_locale, false); | 568 return GetDisplayNameForLocale("_" + country_code, display_locale, false); |
| 568 } | 569 } |
| 569 | 570 |
| 570 std::string NormalizeLocale(const std::string& locale) { | 571 std::string NormalizeLocale(const std::string& locale) { |
| 571 std::string normalized_locale(locale); | 572 std::string normalized_locale(locale); |
| 572 std::replace(normalized_locale.begin(), normalized_locale.end(), '-', '_'); | 573 std::replace(normalized_locale.begin(), normalized_locale.end(), '-', '_'); |
| 573 | 574 |
| 574 return normalized_locale; | 575 return normalized_locale; |
| 575 } | 576 } |
| 576 | 577 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 return false; | 657 return false; |
| 657 } | 658 } |
| 658 | 659 |
| 659 return true; | 660 return true; |
| 660 } | 661 } |
| 661 | 662 |
| 662 std::string GetStringUTF8(int message_id) { | 663 std::string GetStringUTF8(int message_id) { |
| 663 return UTF16ToUTF8(GetStringUTF16(message_id)); | 664 return UTF16ToUTF8(GetStringUTF16(message_id)); |
| 664 } | 665 } |
| 665 | 666 |
| 666 string16 GetStringUTF16(int message_id) { | 667 base::string16 GetStringUTF16(int message_id) { |
| 667 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 668 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 668 string16 str = rb.GetLocalizedString(message_id); | 669 base::string16 str = rb.GetLocalizedString(message_id); |
| 669 AdjustParagraphDirectionality(&str); | 670 AdjustParagraphDirectionality(&str); |
| 670 | 671 |
| 671 return str; | 672 return str; |
| 672 } | 673 } |
| 673 | 674 |
| 674 string16 GetStringFUTF16(int message_id, | 675 base::string16 GetStringFUTF16(int message_id, |
| 675 const std::vector<string16>& replacements, | 676 const std::vector<base::string16>& replacements, |
| 676 std::vector<size_t>* offsets) { | 677 std::vector<size_t>* offsets) { |
| 677 // TODO(tc): We could save a string copy if we got the raw string as | 678 // TODO(tc): We could save a string copy if we got the raw string as |
| 678 // a StringPiece and were able to call ReplaceStringPlaceholders with | 679 // a StringPiece and were able to call ReplaceStringPlaceholders with |
| 679 // a StringPiece format string and string16 substitution strings. In | 680 // a StringPiece format string and base::string16 substitution strings. In |
| 680 // practice, the strings should be relatively short. | 681 // practice, the strings should be relatively short. |
| 681 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 682 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 682 const string16& format_string = rb.GetLocalizedString(message_id); | 683 const base::string16& format_string = rb.GetLocalizedString(message_id); |
| 683 | 684 |
| 684 #ifndef NDEBUG | 685 #ifndef NDEBUG |
| 685 // Make sure every replacement string is being used, so we don't just | 686 // Make sure every replacement string is being used, so we don't just |
| 686 // silently fail to insert one. If |offsets| is non-NULL, then don't do this | 687 // silently fail to insert one. If |offsets| is non-NULL, then don't do this |
| 687 // check as the code may simply want to find the placeholders rather than | 688 // check as the code may simply want to find the placeholders rather than |
| 688 // actually replacing them. | 689 // actually replacing them. |
| 689 if (!offsets) { | 690 if (!offsets) { |
| 690 std::string utf8_string = UTF16ToUTF8(format_string); | 691 std::string utf8_string = UTF16ToUTF8(format_string); |
| 691 | 692 |
| 692 // $9 is the highest allowed placeholder. | 693 // $9 is the highest allowed placeholder. |
| 693 for (size_t i = 0; i < 9; ++i) { | 694 for (size_t i = 0; i < 9; ++i) { |
| 694 bool placeholder_should_exist = replacements.size() > i; | 695 bool placeholder_should_exist = replacements.size() > i; |
| 695 | 696 |
| 696 std::string placeholder = | 697 std::string placeholder = |
| 697 base::StringPrintf("$%d", static_cast<int>(i + 1)); | 698 base::StringPrintf("$%d", static_cast<int>(i + 1)); |
| 698 size_t pos = utf8_string.find(placeholder.c_str()); | 699 size_t pos = utf8_string.find(placeholder.c_str()); |
| 699 if (placeholder_should_exist) { | 700 if (placeholder_should_exist) { |
| 700 DCHECK_NE(std::string::npos, pos) << | 701 DCHECK_NE(std::string::npos, pos) << |
| 701 " Didn't find a " << placeholder << " placeholder in " << | 702 " Didn't find a " << placeholder << " placeholder in " << |
| 702 utf8_string; | 703 utf8_string; |
| 703 } else { | 704 } else { |
| 704 DCHECK_EQ(std::string::npos, pos) << | 705 DCHECK_EQ(std::string::npos, pos) << |
| 705 " Unexpectedly found a " << placeholder << " placeholder in " << | 706 " Unexpectedly found a " << placeholder << " placeholder in " << |
| 706 utf8_string; | 707 utf8_string; |
| 707 } | 708 } |
| 708 } | 709 } |
| 709 } | 710 } |
| 710 #endif | 711 #endif |
| 711 | 712 |
| 712 string16 formatted = ReplaceStringPlaceholders(format_string, replacements, | 713 base::string16 formatted = ReplaceStringPlaceholders( |
| 713 offsets); | 714 format_string, replacements, offsets); |
| 714 AdjustParagraphDirectionality(&formatted); | 715 AdjustParagraphDirectionality(&formatted); |
| 715 | 716 |
| 716 return formatted; | 717 return formatted; |
| 717 } | 718 } |
| 718 | 719 |
| 719 std::string GetStringFUTF8(int message_id, | 720 std::string GetStringFUTF8(int message_id, |
| 720 const string16& a) { | 721 const base::string16& a) { |
| 721 return UTF16ToUTF8(GetStringFUTF16(message_id, a)); | 722 return UTF16ToUTF8(GetStringFUTF16(message_id, a)); |
| 722 } | 723 } |
| 723 | 724 |
| 724 std::string GetStringFUTF8(int message_id, | 725 std::string GetStringFUTF8(int message_id, |
| 725 const string16& a, | 726 const base::string16& a, |
| 726 const string16& b) { | 727 const base::string16& b) { |
| 727 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b)); | 728 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b)); |
| 728 } | 729 } |
| 729 | 730 |
| 730 std::string GetStringFUTF8(int message_id, | 731 std::string GetStringFUTF8(int message_id, |
| 731 const string16& a, | 732 const base::string16& a, |
| 732 const string16& b, | 733 const base::string16& b, |
| 733 const string16& c) { | 734 const base::string16& c) { |
| 734 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b, c)); | 735 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b, c)); |
| 735 } | 736 } |
| 736 | 737 |
| 737 std::string GetStringFUTF8(int message_id, | 738 std::string GetStringFUTF8(int message_id, |
| 738 const string16& a, | 739 const base::string16& a, |
| 739 const string16& b, | 740 const base::string16& b, |
| 740 const string16& c, | 741 const base::string16& c, |
| 741 const string16& d) { | 742 const base::string16& d) { |
| 742 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b, c, d)); | 743 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b, c, d)); |
| 743 } | 744 } |
| 744 | 745 |
| 745 string16 GetStringFUTF16(int message_id, | 746 base::string16 GetStringFUTF16(int message_id, |
| 746 const string16& a) { | 747 const base::string16& a) { |
| 747 std::vector<string16> replacements; | 748 std::vector<base::string16> replacements; |
| 748 replacements.push_back(a); | 749 replacements.push_back(a); |
| 749 return GetStringFUTF16(message_id, replacements, NULL); | 750 return GetStringFUTF16(message_id, replacements, NULL); |
| 750 } | 751 } |
| 751 | 752 |
| 752 string16 GetStringFUTF16(int message_id, | 753 base::string16 GetStringFUTF16(int message_id, |
| 753 const string16& a, | 754 const base::string16& a, |
| 754 const string16& b) { | 755 const base::string16& b) { |
| 755 return GetStringFUTF16(message_id, a, b, NULL); | 756 return GetStringFUTF16(message_id, a, b, NULL); |
| 756 } | 757 } |
| 757 | 758 |
| 758 string16 GetStringFUTF16(int message_id, | 759 base::string16 GetStringFUTF16(int message_id, |
| 759 const string16& a, | 760 const base::string16& a, |
| 760 const string16& b, | 761 const base::string16& b, |
| 761 const string16& c) { | 762 const base::string16& c) { |
| 762 std::vector<string16> replacements; | 763 std::vector<base::string16> replacements; |
| 763 replacements.push_back(a); | 764 replacements.push_back(a); |
| 764 replacements.push_back(b); | 765 replacements.push_back(b); |
| 765 replacements.push_back(c); | 766 replacements.push_back(c); |
| 766 return GetStringFUTF16(message_id, replacements, NULL); | 767 return GetStringFUTF16(message_id, replacements, NULL); |
| 767 } | 768 } |
| 768 | 769 |
| 769 string16 GetStringFUTF16(int message_id, | 770 base::string16 GetStringFUTF16(int message_id, |
| 770 const string16& a, | 771 const base::string16& a, |
| 771 const string16& b, | 772 const base::string16& b, |
| 772 const string16& c, | 773 const base::string16& c, |
| 773 const string16& d) { | 774 const base::string16& d) { |
| 774 std::vector<string16> replacements; | 775 std::vector<base::string16> replacements; |
| 775 replacements.push_back(a); | 776 replacements.push_back(a); |
| 776 replacements.push_back(b); | 777 replacements.push_back(b); |
| 777 replacements.push_back(c); | 778 replacements.push_back(c); |
| 778 replacements.push_back(d); | 779 replacements.push_back(d); |
| 779 return GetStringFUTF16(message_id, replacements, NULL); | 780 return GetStringFUTF16(message_id, replacements, NULL); |
| 780 } | 781 } |
| 781 | 782 |
| 782 string16 GetStringFUTF16(int message_id, | 783 base::string16 GetStringFUTF16(int message_id, |
| 783 const string16& a, | 784 const base::string16& a, |
| 784 const string16& b, | 785 const base::string16& b, |
| 785 const string16& c, | 786 const base::string16& c, |
| 786 const string16& d, | 787 const base::string16& d, |
| 787 const string16& e) { | 788 const base::string16& e) { |
| 788 std::vector<string16> replacements; | 789 std::vector<base::string16> replacements; |
| 789 replacements.push_back(a); | 790 replacements.push_back(a); |
| 790 replacements.push_back(b); | 791 replacements.push_back(b); |
| 791 replacements.push_back(c); | 792 replacements.push_back(c); |
| 792 replacements.push_back(d); | 793 replacements.push_back(d); |
| 793 replacements.push_back(e); | 794 replacements.push_back(e); |
| 794 return GetStringFUTF16(message_id, replacements, NULL); | 795 return GetStringFUTF16(message_id, replacements, NULL); |
| 795 } | 796 } |
| 796 | 797 |
| 797 string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset) { | 798 base::string16 GetStringFUTF16(int message_id, |
| 799 const base::string16& a, |
| 800 size_t* offset) { |
| 798 DCHECK(offset); | 801 DCHECK(offset); |
| 799 std::vector<size_t> offsets; | 802 std::vector<size_t> offsets; |
| 800 std::vector<string16> replacements; | 803 std::vector<base::string16> replacements; |
| 801 replacements.push_back(a); | 804 replacements.push_back(a); |
| 802 string16 result = GetStringFUTF16(message_id, replacements, &offsets); | 805 base::string16 result = GetStringFUTF16(message_id, replacements, &offsets); |
| 803 DCHECK(offsets.size() == 1); | 806 DCHECK(offsets.size() == 1); |
| 804 *offset = offsets[0]; | 807 *offset = offsets[0]; |
| 805 return result; | 808 return result; |
| 806 } | 809 } |
| 807 | 810 |
| 808 string16 GetStringFUTF16(int message_id, | 811 base::string16 GetStringFUTF16(int message_id, |
| 809 const string16& a, | 812 const base::string16& a, |
| 810 const string16& b, | 813 const base::string16& b, |
| 811 std::vector<size_t>* offsets) { | 814 std::vector<size_t>* offsets) { |
| 812 std::vector<string16> replacements; | 815 std::vector<base::string16> replacements; |
| 813 replacements.push_back(a); | 816 replacements.push_back(a); |
| 814 replacements.push_back(b); | 817 replacements.push_back(b); |
| 815 return GetStringFUTF16(message_id, replacements, offsets); | 818 return GetStringFUTF16(message_id, replacements, offsets); |
| 816 } | 819 } |
| 817 | 820 |
| 818 string16 GetStringFUTF16Int(int message_id, int a) { | 821 base::string16 GetStringFUTF16Int(int message_id, int a) { |
| 819 return GetStringFUTF16(message_id, UTF8ToUTF16(base::IntToString(a))); | 822 return GetStringFUTF16(message_id, UTF8ToUTF16(base::IntToString(a))); |
| 820 } | 823 } |
| 821 | 824 |
| 822 string16 GetStringFUTF16Int(int message_id, int64 a) { | 825 base::string16 GetStringFUTF16Int(int message_id, int64 a) { |
| 823 return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a))); | 826 return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a))); |
| 824 } | 827 } |
| 825 | 828 |
| 826 // Specialization of operator() method for string16 version. | 829 // Specialization of operator() method for base::string16 version. |
| 827 template <> | 830 template <> |
| 828 bool StringComparator<string16>::operator()(const string16& lhs, | 831 bool StringComparator<base::string16>::operator()(const base::string16& lhs, |
| 829 const string16& rhs) { | 832 const base::string16& rhs) { |
| 830 // If we can not get collator instance for specified locale, just do simple | 833 // If we can not get collator instance for specified locale, just do simple |
| 831 // string compare. | 834 // string compare. |
| 832 if (!collator_) | 835 if (!collator_) |
| 833 return lhs < rhs; | 836 return lhs < rhs; |
| 834 return base::i18n::CompareString16WithCollator(collator_, lhs, rhs) == | 837 return base::i18n::CompareString16WithCollator(collator_, lhs, rhs) == |
| 835 UCOL_LESS; | 838 UCOL_LESS; |
| 836 }; | 839 }; |
| 837 | 840 |
| 838 string16 GetPluralStringFUTF16(const std::vector<int>& message_ids, | 841 base::string16 GetPluralStringFUTF16(const std::vector<int>& message_ids, |
| 839 int number) { | 842 int number) { |
| 840 scoped_ptr<icu::PluralFormat> format = BuildPluralFormat(message_ids); | 843 scoped_ptr<icu::PluralFormat> format = BuildPluralFormat(message_ids); |
| 841 DCHECK(format); | 844 DCHECK(format); |
| 842 | 845 |
| 843 UErrorCode err = U_ZERO_ERROR; | 846 UErrorCode err = U_ZERO_ERROR; |
| 844 icu::UnicodeString result_files_string = format->format(number, err); | 847 icu::UnicodeString result_files_string = format->format(number, err); |
| 845 int capacity = result_files_string.length() + 1; | 848 int capacity = result_files_string.length() + 1; |
| 846 DCHECK_GT(capacity, 1); | 849 DCHECK_GT(capacity, 1); |
| 847 string16 result; | 850 base::string16 result; |
| 848 result_files_string.extract( | 851 result_files_string.extract( |
| 849 static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err); | 852 static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err); |
| 850 DCHECK(U_SUCCESS(err)); | 853 DCHECK(U_SUCCESS(err)); |
| 851 return result; | 854 return result; |
| 852 } | 855 } |
| 853 | 856 |
| 854 std::string GetPluralStringFUTF8(const std::vector<int>& message_ids, | 857 std::string GetPluralStringFUTF8(const std::vector<int>& message_ids, |
| 855 int number) { | 858 int number) { |
| 856 return base::UTF16ToUTF8(GetPluralStringFUTF16(message_ids, number)); | 859 return base::UTF16ToUTF8(GetPluralStringFUTF16(message_ids, number)); |
| 857 } | 860 } |
| 858 | 861 |
| 859 void SortStrings16(const std::string& locale, | 862 void SortStrings16(const std::string& locale, |
| 860 std::vector<string16>* strings) { | 863 std::vector<base::string16>* strings) { |
| 861 SortVectorWithStringKey(locale, strings, false); | 864 SortVectorWithStringKey(locale, strings, false); |
| 862 } | 865 } |
| 863 | 866 |
| 864 const std::vector<std::string>& GetAvailableLocales() { | 867 const std::vector<std::string>& GetAvailableLocales() { |
| 865 return g_available_locales.Get(); | 868 return g_available_locales.Get(); |
| 866 } | 869 } |
| 867 | 870 |
| 868 void GetAcceptLanguagesForLocale(const std::string& display_locale, | 871 void GetAcceptLanguagesForLocale(const std::string& display_locale, |
| 869 std::vector<std::string>* locale_codes) { | 872 std::vector<std::string>* locale_codes) { |
| 870 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 873 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { |
| 871 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i], | 874 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i], |
| 872 display_locale)) | 875 display_locale)) |
| 873 // TODO(jungshik) : Put them at the of the list with language codes | 876 // TODO(jungshik) : Put them at the of the list with language codes |
| 874 // enclosed by brackets instead of skipping. | 877 // enclosed by brackets instead of skipping. |
| 875 continue; | 878 continue; |
| 876 locale_codes->push_back(kAcceptLanguageList[i]); | 879 locale_codes->push_back(kAcceptLanguageList[i]); |
| 877 } | 880 } |
| 878 } | 881 } |
| 879 | 882 |
| 880 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { | 883 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { |
| 881 int width = 0; | 884 int width = 0; |
| 882 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); | 885 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); |
| 883 DCHECK_GT(width, 0); | 886 DCHECK_GT(width, 0); |
| 884 return width; | 887 return width; |
| 885 } | 888 } |
| 886 | 889 |
| 887 } // namespace l10n_util | 890 } // namespace l10n_util |
| OLD | NEW |