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

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

Issue 23591040: Use ICU for string pluralization in the extension permission dialog. (Closed) Base URL: http://git.chromium.org/chromium/src.git@gtk-extension-install-dialog
Patch Set: Created 7 years, 2 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 10 matching lines...) Expand all
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h" 22 #include "base/strings/string_split.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/sys_string_conversions.h" 25 #include "base/strings/sys_string_conversions.h"
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "third_party/icu/source/common/unicode/rbbi.h" 28 #include "third_party/icu/source/common/unicode/rbbi.h"
29 #include "third_party/icu/source/common/unicode/uloc.h" 29 #include "third_party/icu/source/common/unicode/uloc.h"
30 #include "ui/base/l10n/l10n_util_collator.h" 30 #include "ui/base/l10n/l10n_util_collator.h"
31 #include "ui/base/l10n/l10n_util_plurals.h"
31 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/base/ui_base_paths.h" 33 #include "ui/base/ui_base_paths.h"
33 34
34 #if defined(OS_ANDROID) 35 #if defined(OS_ANDROID)
35 #include "ui/base/l10n/l10n_util_android.h" 36 #include "ui/base/l10n/l10n_util_android.h"
36 #endif 37 #endif
37 38
38 #if defined(OS_LINUX) 39 #if defined(OS_LINUX)
39 #include <glib.h> 40 #include <glib.h>
40 #endif 41 #endif
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 bool StringComparator<string16>::operator()(const string16& lhs, 825 bool StringComparator<string16>::operator()(const string16& lhs,
825 const string16& rhs) { 826 const string16& rhs) {
826 // If we can not get collator instance for specified locale, just do simple 827 // If we can not get collator instance for specified locale, just do simple
827 // string compare. 828 // string compare.
828 if (!collator_) 829 if (!collator_)
829 return lhs < rhs; 830 return lhs < rhs;
830 return base::i18n::CompareString16WithCollator(collator_, lhs, rhs) == 831 return base::i18n::CompareString16WithCollator(collator_, lhs, rhs) ==
831 UCOL_LESS; 832 UCOL_LESS;
832 }; 833 };
833 834
835 string16 GetPluralStringFUTF16(const std::vector<int>& message_ids,
836 int number) {
837 scoped_ptr<icu::PluralFormat> format = BuildPluralFormat(message_ids);
838 DCHECK(format);
839
840 UErrorCode err = U_ZERO_ERROR;
841 icu::UnicodeString result_files_string = format->format(number, err);
842 int capacity = result_files_string.length() + 1;
843 DCHECK_GT(capacity, 1);
844 string16 result;
845 result_files_string.extract(
846 static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err);
847 DCHECK(U_SUCCESS(err));
848 return result;
849 }
850
851 std::string GetPluralStringFUTF8(const std::vector<int>& message_ids,
852 int number) {
853 return base::UTF16ToUTF8(GetPluralStringFUTF16(message_ids, number));
854 }
855
834 void SortStrings16(const std::string& locale, 856 void SortStrings16(const std::string& locale,
835 std::vector<string16>* strings) { 857 std::vector<string16>* strings) {
836 SortVectorWithStringKey(locale, strings, false); 858 SortVectorWithStringKey(locale, strings, false);
837 } 859 }
838 860
839 const std::vector<std::string>& GetAvailableLocales() { 861 const std::vector<std::string>& GetAvailableLocales() {
840 return g_available_locales.Get(); 862 return g_available_locales.Get();
841 } 863 }
842 864
843 void GetAcceptLanguagesForLocale(const std::string& display_locale, 865 void GetAcceptLanguagesForLocale(const std::string& display_locale,
844 std::vector<std::string>* locale_codes) { 866 std::vector<std::string>* locale_codes) {
845 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { 867 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) {
846 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i], 868 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i],
847 display_locale)) 869 display_locale))
848 // TODO(jungshik) : Put them at the of the list with language codes 870 // TODO(jungshik) : Put them at the of the list with language codes
849 // enclosed by brackets instead of skipping. 871 // enclosed by brackets instead of skipping.
850 continue; 872 continue;
851 locale_codes->push_back(kAcceptLanguageList[i]); 873 locale_codes->push_back(kAcceptLanguageList[i]);
852 } 874 }
853 } 875 }
854 876
855 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { 877 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) {
856 int width = 0; 878 int width = 0;
857 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); 879 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width);
858 DCHECK_GT(width, 0); 880 DCHECK_GT(width, 0);
859 return width; 881 return width;
860 } 882 }
861 883
862 } // namespace l10n_util 884 } // 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