| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 5 #include "app/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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 561   } | 561   } | 
| 562   if (token_index == 0 && (token_len < 1 || token_len > 3)) { | 562   if (token_index == 0 && (token_len < 1 || token_len > 3)) { | 
| 563     return false; | 563     return false; | 
| 564   } else if (token_len < 1 || token_len > 8) { | 564   } else if (token_len < 1 || token_len > 8) { | 
| 565     return false; | 565     return false; | 
| 566   } | 566   } | 
| 567 | 567 | 
| 568   return true; | 568   return true; | 
| 569 } | 569 } | 
| 570 | 570 | 
|  | 571 #if CRBUG_9911_OBSOLETE_GOING_AWAY | 
| 571 std::wstring GetString(int message_id) { | 572 std::wstring GetString(int message_id) { | 
| 572   return UTF16ToWide(GetStringUTF16(message_id)); | 573   return UTF16ToWide(GetStringUTF16(message_id)); | 
| 573 } | 574 } | 
|  | 575 #endif | 
| 574 | 576 | 
| 575 std::string GetStringUTF8(int message_id) { | 577 std::string GetStringUTF8(int message_id) { | 
| 576   return UTF16ToUTF8(GetStringUTF16(message_id)); | 578   return UTF16ToUTF8(GetStringUTF16(message_id)); | 
| 577 } | 579 } | 
| 578 | 580 | 
| 579 string16 GetStringUTF16(int message_id) { | 581 string16 GetStringUTF16(int message_id) { | 
| 580   ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 582   ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 
| 581   string16 str = rb.GetLocalizedString(message_id); | 583   string16 str = rb.GetLocalizedString(message_id); | 
| 582   AdjustParagraphDirectionality(&str); | 584   AdjustParagraphDirectionality(&str); | 
| 583 | 585 | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 621   } | 623   } | 
| 622 #endif | 624 #endif | 
| 623 | 625 | 
| 624   string16 formatted = ReplaceStringPlaceholders(format_string, replacements, | 626   string16 formatted = ReplaceStringPlaceholders(format_string, replacements, | 
| 625                                                  offsets); | 627                                                  offsets); | 
| 626   AdjustParagraphDirectionality(&formatted); | 628   AdjustParagraphDirectionality(&formatted); | 
| 627 | 629 | 
| 628   return formatted; | 630   return formatted; | 
| 629 } | 631 } | 
| 630 | 632 | 
|  | 633 #if CRBUG_9911_OBSOLETE_GOING_AWAY | 
| 631 #if !defined(WCHAR_T_IS_UTF16) | 634 #if !defined(WCHAR_T_IS_UTF16) | 
| 632 std::wstring GetStringF(int message_id, const std::wstring& a) { | 635 std::wstring GetStringF(int message_id, const std::wstring& a) { | 
| 633   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a))); | 636   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a))); | 
| 634 } | 637 } | 
| 635 | 638 | 
| 636 std::wstring GetStringF(int message_id, | 639 std::wstring GetStringF(int message_id, | 
| 637                         const std::wstring& a, | 640                         const std::wstring& a, | 
| 638                         const std::wstring& b) { | 641                         const std::wstring& b) { | 
| 639   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a), | 642   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a), | 
| 640                                      WideToUTF16(b))); | 643                                      WideToUTF16(b))); | 
| 641 } | 644 } | 
| 642 | 645 | 
| 643 std::wstring GetStringF(int message_id, | 646 std::wstring GetStringF(int message_id, | 
| 644                         const std::wstring& a, | 647                         const std::wstring& a, | 
| 645                         const std::wstring& b, | 648                         const std::wstring& b, | 
| 646                         const std::wstring& c) { | 649                         const std::wstring& c) { | 
| 647   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a), | 650   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a), | 
| 648                                      WideToUTF16(b), WideToUTF16(c))); | 651                                      WideToUTF16(b), WideToUTF16(c))); | 
| 649 } | 652 } | 
| 650 | 653 | 
| 651 std::wstring GetStringF(int message_id, | 654 std::wstring GetStringF(int message_id, | 
| 652                         const std::wstring& a, | 655                         const std::wstring& a, | 
| 653                         const std::wstring& b, | 656                         const std::wstring& b, | 
| 654                         const std::wstring& c, | 657                         const std::wstring& c, | 
| 655                         const std::wstring& d) { | 658                         const std::wstring& d) { | 
| 656   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a), WideToUTF16(b), | 659   return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a), WideToUTF16(b), | 
| 657                                      WideToUTF16(c), WideToUTF16(d))); | 660                                      WideToUTF16(c), WideToUTF16(d))); | 
| 658 } | 661 } | 
| 659 #endif | 662 #endif | 
|  | 663 #endif | 
| 660 | 664 | 
| 661 std::string GetStringFUTF8(int message_id, | 665 std::string GetStringFUTF8(int message_id, | 
| 662                            const string16& a) { | 666                            const string16& a) { | 
| 663   return UTF16ToUTF8(GetStringFUTF16(message_id, a)); | 667   return UTF16ToUTF8(GetStringFUTF16(message_id, a)); | 
| 664 } | 668 } | 
| 665 | 669 | 
| 666 std::string GetStringFUTF8(int message_id, | 670 std::string GetStringFUTF8(int message_id, | 
| 667                            const string16& a, | 671                            const string16& a, | 
| 668                            const string16& b) { | 672                            const string16& b) { | 
| 669   return UTF16ToUTF8(GetStringFUTF16(message_id, a, b)); | 673   return UTF16ToUTF8(GetStringFUTF16(message_id, a, b)); | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 714                          const string16& c, | 718                          const string16& c, | 
| 715                          const string16& d) { | 719                          const string16& d) { | 
| 716   std::vector<string16> replacements; | 720   std::vector<string16> replacements; | 
| 717   replacements.push_back(a); | 721   replacements.push_back(a); | 
| 718   replacements.push_back(b); | 722   replacements.push_back(b); | 
| 719   replacements.push_back(c); | 723   replacements.push_back(c); | 
| 720   replacements.push_back(d); | 724   replacements.push_back(d); | 
| 721   return GetStringF(message_id, replacements, NULL); | 725   return GetStringF(message_id, replacements, NULL); | 
| 722 } | 726 } | 
| 723 | 727 | 
|  | 728 #if CRBUG_9911_OBSOLETE_GOING_AWAY | 
| 724 std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset) { | 729 std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset) { | 
| 725   DCHECK(offset); | 730   DCHECK(offset); | 
| 726   std::vector<size_t> offsets; | 731   std::vector<size_t> offsets; | 
| 727   std::vector<string16> replacements; | 732   std::vector<string16> replacements; | 
| 728   replacements.push_back(WideToUTF16(a)); | 733   replacements.push_back(WideToUTF16(a)); | 
| 729   string16 result = GetStringF(message_id, replacements, &offsets); | 734   string16 result = GetStringF(message_id, replacements, &offsets); | 
| 730   DCHECK(offsets.size() == 1); | 735   DCHECK(offsets.size() == 1); | 
| 731   *offset = offsets[0]; | 736   *offset = offsets[0]; | 
| 732   return UTF16ToWide(result); | 737   return UTF16ToWide(result); | 
| 733 } | 738 } | 
| 734 | 739 | 
| 735 std::wstring GetStringF(int message_id, | 740 std::wstring GetStringF(int message_id, | 
| 736                         const std::wstring& a, | 741                         const std::wstring& a, | 
| 737                         const std::wstring& b, | 742                         const std::wstring& b, | 
| 738                         std::vector<size_t>* offsets) { | 743                         std::vector<size_t>* offsets) { | 
| 739   std::vector<string16> replacements; | 744   std::vector<string16> replacements; | 
| 740   replacements.push_back(WideToUTF16(a)); | 745   replacements.push_back(WideToUTF16(a)); | 
| 741   replacements.push_back(WideToUTF16(b)); | 746   replacements.push_back(WideToUTF16(b)); | 
| 742   return UTF16ToWide(GetStringF(message_id, replacements, offsets)); | 747   return UTF16ToWide(GetStringF(message_id, replacements, offsets)); | 
| 743 } | 748 } | 
|  | 749 #endif | 
| 744 | 750 | 
| 745 string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset) { | 751 string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset) { | 
| 746   DCHECK(offset); | 752   DCHECK(offset); | 
| 747   std::vector<size_t> offsets; | 753   std::vector<size_t> offsets; | 
| 748   std::vector<string16> replacements; | 754   std::vector<string16> replacements; | 
| 749   replacements.push_back(a); | 755   replacements.push_back(a); | 
| 750   string16 result = GetStringF(message_id, replacements, &offsets); | 756   string16 result = GetStringF(message_id, replacements, &offsets); | 
| 751   DCHECK(offsets.size() == 1); | 757   DCHECK(offsets.size() == 1); | 
| 752   *offset = offsets[0]; | 758   *offset = offsets[0]; | 
| 753   return result; | 759   return result; | 
| 754 } | 760 } | 
| 755 | 761 | 
| 756 string16 GetStringFUTF16(int message_id, | 762 string16 GetStringFUTF16(int message_id, | 
| 757                          const string16& a, | 763                          const string16& a, | 
| 758                          const string16& b, | 764                          const string16& b, | 
| 759                          std::vector<size_t>* offsets) { | 765                          std::vector<size_t>* offsets) { | 
| 760   std::vector<string16> replacements; | 766   std::vector<string16> replacements; | 
| 761   replacements.push_back(a); | 767   replacements.push_back(a); | 
| 762   replacements.push_back(b); | 768   replacements.push_back(b); | 
| 763   return GetStringF(message_id, replacements, offsets); | 769   return GetStringF(message_id, replacements, offsets); | 
| 764 } | 770 } | 
| 765 | 771 | 
|  | 772 #if CRBUG_9911_OBSOLETE_GOING_AWAY | 
| 766 std::wstring GetStringF(int message_id, int a) { | 773 std::wstring GetStringF(int message_id, int a) { | 
| 767   return GetStringF(message_id, UTF8ToWide(base::IntToString(a))); | 774   return GetStringF(message_id, UTF8ToWide(base::IntToString(a))); | 
| 768 } | 775 } | 
| 769 | 776 | 
| 770 std::wstring GetStringF(int message_id, int64 a) { | 777 std::wstring GetStringF(int message_id, int64 a) { | 
| 771   return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a))); | 778   return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a))); | 
| 772 } | 779 } | 
|  | 780 #endif | 
|  | 781 | 
|  | 782 string16 GetStringFUTF16(int message_id, int a) { | 
|  | 783   return GetStringFUTF16(message_id, UTF8ToUTF16(base::IntToString(a))); | 
|  | 784 } | 
|  | 785 | 
|  | 786 string16 GetStringFUTF16(int message_id, int64 a) { | 
|  | 787   return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a))); | 
|  | 788 } | 
| 773 | 789 | 
| 774 string16 TruncateString(const string16& string, size_t length) { | 790 string16 TruncateString(const string16& string, size_t length) { | 
| 775   if (string.size() <= length) | 791   if (string.size() <= length) | 
| 776     // String fits, return it. | 792     // String fits, return it. | 
| 777     return string; | 793     return string; | 
| 778 | 794 | 
| 779   if (length == 0) { | 795   if (length == 0) { | 
| 780     // No room for the elide string, return an empty string. | 796     // No room for the elide string, return an empty string. | 
| 781     return string16(); | 797     return string16(); | 
| 782   } | 798   } | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 880   string16 lhs_utf16 = WideToUTF16(lhs); | 896   string16 lhs_utf16 = WideToUTF16(lhs); | 
| 881   string16 rhs_utf16 = WideToUTF16(rhs); | 897   string16 rhs_utf16 = WideToUTF16(rhs); | 
| 882 | 898 | 
| 883   result = CompareString16WithCollator(collator, lhs_utf16, rhs_utf16); | 899   result = CompareString16WithCollator(collator, lhs_utf16, rhs_utf16); | 
| 884 #else | 900 #else | 
| 885   result = CompareString16WithCollator(collator, lhs, rhs); | 901   result = CompareString16WithCollator(collator, lhs, rhs); | 
| 886 #endif | 902 #endif | 
| 887   return result; | 903   return result; | 
| 888 } | 904 } | 
| 889 | 905 | 
| 890 // Specialization of operator() method for std::wstring version. |  | 
| 891 template <> |  | 
| 892 bool StringComparator<std::wstring>::operator()(const std::wstring& lhs, |  | 
| 893                                                 const std::wstring& rhs) { |  | 
| 894   // If we can not get collator instance for specified locale, just do simple |  | 
| 895   // string compare. |  | 
| 896   if (!collator_) |  | 
| 897     return lhs < rhs; |  | 
| 898   return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS; |  | 
| 899 }; |  | 
| 900 |  | 
| 901 #if !defined(WCHAR_T_IS_UTF16) |  | 
| 902 // Specialization of operator() method for string16 version. | 906 // Specialization of operator() method for string16 version. | 
| 903 template <> | 907 template <> | 
| 904 bool StringComparator<string16>::operator()(const string16& lhs, | 908 bool StringComparator<string16>::operator()(const string16& lhs, | 
| 905                                             const string16& rhs) { | 909                                             const string16& rhs) { | 
| 906   // If we can not get collator instance for specified locale, just do simple | 910   // If we can not get collator instance for specified locale, just do simple | 
| 907   // string compare. | 911   // string compare. | 
| 908   if (!collator_) | 912   if (!collator_) | 
| 909     return lhs < rhs; | 913     return lhs < rhs; | 
| 910   return CompareString16WithCollator(collator_, lhs, rhs) == UCOL_LESS; | 914   return CompareString16WithCollator(collator_, lhs, rhs) == UCOL_LESS; | 
| 911 }; | 915 }; | 
| 912 #endif  // !defined(WCHAR_T_IS_UTF16) |  | 
| 913 |  | 
| 914 void SortStrings(const std::string& locale, |  | 
| 915                  std::vector<std::wstring>* strings) { |  | 
| 916   SortVectorWithStringKey(locale, strings, false); |  | 
| 917 } |  | 
| 918 | 916 | 
| 919 void SortStrings16(const std::string& locale, | 917 void SortStrings16(const std::string& locale, | 
| 920                    std::vector<string16>* strings) { | 918                    std::vector<string16>* strings) { | 
| 921   SortVectorWithStringKey(locale, strings, false); | 919   SortVectorWithStringKey(locale, strings, false); | 
| 922 } | 920 } | 
| 923 | 921 | 
| 924 const std::vector<std::string>& GetAvailableLocales() { | 922 const std::vector<std::string>& GetAvailableLocales() { | 
| 925   static std::vector<std::string> locales; | 923   static std::vector<std::string> locales; | 
| 926   if (locales.empty()) { | 924   if (locales.empty()) { | 
| 927     int num_locales = uloc_countAvailable(); | 925     int num_locales = uloc_countAvailable(); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 960   for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 958   for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 
| 961     if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) | 959     if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) | 
| 962       // TODO(jungshik) : Put them at the of the list with language codes | 960       // TODO(jungshik) : Put them at the of the list with language codes | 
| 963       // enclosed by brackets instead of skipping. | 961       // enclosed by brackets instead of skipping. | 
| 964         continue; | 962         continue; | 
| 965     locale_codes->push_back(kAcceptLanguageList[i]); | 963     locale_codes->push_back(kAcceptLanguageList[i]); | 
| 966   } | 964   } | 
| 967 } | 965 } | 
| 968 | 966 | 
| 969 }  // namespace l10n_util | 967 }  // namespace l10n_util | 
| OLD | NEW | 
|---|