Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: ui/base/l10n/l10n_util.cc

Issue 1049513002: Use the ICU syntax message for plural formatting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ios whitelist update Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/l10n/l10n_util.h ('k') | ui/base/l10n/l10n_util_plurals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 } 816 }
817 817
818 base::string16 GetStringFUTF16Int(int message_id, int a) { 818 base::string16 GetStringFUTF16Int(int message_id, int a) {
819 return GetStringFUTF16(message_id, base::UTF8ToUTF16(base::IntToString(a))); 819 return GetStringFUTF16(message_id, base::UTF8ToUTF16(base::IntToString(a)));
820 } 820 }
821 821
822 base::string16 GetStringFUTF16Int(int message_id, int64 a) { 822 base::string16 GetStringFUTF16Int(int message_id, int64 a) {
823 return GetStringFUTF16(message_id, base::UTF8ToUTF16(base::Int64ToString(a))); 823 return GetStringFUTF16(message_id, base::UTF8ToUTF16(base::Int64ToString(a)));
824 } 824 }
825 825
826 base::string16 GetPluralStringFUTF16(const std::vector<int>& message_ids, 826 base::string16 GetPluralStringFUTF16(int message_id, int number) {
827 int number) { 827 base::string16 pattern = GetStringUTF16(message_id);
828 scoped_ptr<icu::PluralFormat> format = BuildPluralFormat(message_ids);
829 DCHECK(format);
830
831 UErrorCode err = U_ZERO_ERROR; 828 UErrorCode err = U_ZERO_ERROR;
832 icu::UnicodeString result_files_string = format->format(number, err); 829 icu::MessageFormat format(
833 int capacity = result_files_string.length() + 1; 830 icu::UnicodeString(FALSE, pattern.data(), pattern.length()), err);
831 icu::UnicodeString result_unistring;
832 FormatNumberInPlural(format, number, &result_unistring, &err);
833 int capacity = result_unistring.length() + 1;
834 DCHECK_GT(capacity, 1); 834 DCHECK_GT(capacity, 1);
835 base::string16 result; 835 base::string16 result;
836 result_files_string.extract( 836 result_unistring.extract(
837 static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err); 837 static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err);
838 DCHECK(U_SUCCESS(err)); 838 DCHECK(U_SUCCESS(err));
839 return result; 839 return result;
840 } 840 }
841 841
842 std::string GetPluralStringFUTF8(const std::vector<int>& message_ids, 842 std::string GetPluralStringFUTF8(int message_id, int number) {
843 int number) { 843 return base::UTF16ToUTF8(GetPluralStringFUTF16(message_id, number));
844 return base::UTF16ToUTF8(GetPluralStringFUTF16(message_ids, number));
845 } 844 }
846 845
847 void SortStrings16(const std::string& locale, 846 void SortStrings16(const std::string& locale,
848 std::vector<base::string16>* strings) { 847 std::vector<base::string16>* strings) {
849 SortVectorWithStringKey(locale, strings, false); 848 SortVectorWithStringKey(locale, strings, false);
850 } 849 }
851 850
852 const std::vector<std::string>& GetAvailableLocales() { 851 const std::vector<std::string>& GetAvailableLocales() {
853 return g_available_locales.Get(); 852 return g_available_locales.Get();
854 } 853 }
(...skipping 19 matching lines...) Expand all
874 873
875 const char* const* GetAcceptLanguageListForTesting() { 874 const char* const* GetAcceptLanguageListForTesting() {
876 return kAcceptLanguageList; 875 return kAcceptLanguageList;
877 } 876 }
878 877
879 size_t GetAcceptLanguageListSizeForTesting() { 878 size_t GetAcceptLanguageListSizeForTesting() {
880 return arraysize(kAcceptLanguageList); 879 return arraysize(kAcceptLanguageList);
881 } 880 }
882 881
883 } // namespace l10n_util 882 } // namespace l10n_util
OLDNEW
« no previous file with comments | « ui/base/l10n/l10n_util.h ('k') | ui/base/l10n/l10n_util_plurals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698