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

Unified Diff: ui/base/l10n/l10n_util_plurals.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/l10n/l10n_util_plurals.h ('k') | ui/base/l10n/time_format.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/l10n/l10n_util_plurals.cc
diff --git a/ui/base/l10n/l10n_util_plurals.cc b/ui/base/l10n/l10n_util_plurals.cc
index afc36a8528292e2dcc1bcafe51cd8d2ce5a2eed1..177e263cf24429218c6ae9394d9a37566f0df94f 100644
--- a/ui/base/l10n/l10n_util_plurals.cc
+++ b/ui/base/l10n/l10n_util_plurals.cc
@@ -23,43 +23,15 @@ scoped_ptr<icu::PluralRules> BuildPluralRules() {
return rules.Pass();
}
-scoped_ptr<icu::PluralFormat> BuildPluralFormat(
- const std::vector<int>& message_ids) {
- const icu::UnicodeString kKeywords[] = {
- UNICODE_STRING_SIMPLE("other"),
- UNICODE_STRING_SIMPLE("one"),
- UNICODE_STRING_SIMPLE("zero"),
- UNICODE_STRING_SIMPLE("two"),
- UNICODE_STRING_SIMPLE("few"),
- UNICODE_STRING_SIMPLE("many"),
- };
- DCHECK_EQ(message_ids.size(), arraysize(kKeywords));
- UErrorCode err = U_ZERO_ERROR;
- scoped_ptr<icu::PluralRules> rules(BuildPluralRules());
-
- icu::UnicodeString pattern;
- for (size_t i = 0; i < arraysize(kKeywords); ++i) {
- int msg_id = message_ids[i];
- std::string sub_pattern = GetStringUTF8(msg_id);
- // NA means this keyword is not used in the current locale.
- // Even if a translator translated for this keyword, we do not
- // use it unless it's 'other' (i=0) or it's defined in the rules
- // for the current locale. Special-casing of 'other' will be removed
- // once ICU's isKeyword is fixed to return true for isKeyword('other').
- if (sub_pattern.compare("NA") != 0 &&
- (i == 0 || rules->isKeyword(kKeywords[i]))) {
- pattern += kKeywords[i];
- pattern += UNICODE_STRING_SIMPLE("{");
- pattern += icu::UnicodeString(sub_pattern.c_str(), "UTF-8");
- pattern += UNICODE_STRING_SIMPLE("}");
- }
- }
- scoped_ptr<icu::PluralFormat> format =
- make_scoped_ptr(new icu::PluralFormat(*rules, pattern, err));
- if (!U_SUCCESS(err)) {
- return nullptr;
- }
- return format.Pass();
+void FormatNumberInPlural(const icu::MessageFormat& format, int number,
+ icu::UnicodeString* result, UErrorCode* err) {
+ if (U_FAILURE(*err)) return;
+ icu::Formattable formattable(number);
+ icu::FieldPosition ignore(icu::FieldPosition::DONT_CARE);
+ format.format(&formattable, 1, *result, ignore, *err);
+ DCHECK(U_SUCCESS(*err));
+ return;
}
+
} // namespace l10n_util
« no previous file with comments | « ui/base/l10n/l10n_util_plurals.h ('k') | ui/base/l10n/time_format.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698