1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/l10n/l10n_util_plurals.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/base/l10n/l10n_util.h"
13 scoped_ptr
<icu::PluralRules
> BuildPluralRules() {
14 UErrorCode err
= U_ZERO_ERROR
;
15 scoped_ptr
<icu::PluralRules
> rules(
16 icu::PluralRules::forLocale(icu::Locale::getDefault(), err
));
19 icu::UnicodeString
fallback_rules("one: n is 1", -1, US_INV
);
20 rules
.reset(icu::PluralRules::createRules(fallback_rules
, err
));
21 DCHECK(U_SUCCESS(err
));
26 void FormatNumberInPlural(const icu::MessageFormat
& format
, int number
,
27 icu::UnicodeString
* result
, UErrorCode
* err
) {
28 if (U_FAILURE(*err
)) return;
29 icu::Formattable
formattable(number
);
30 icu::FieldPosition
ignore(icu::FieldPosition::DONT_CARE
);
31 format
.format(&formattable
, 1, *result
, ignore
, *err
);
32 DCHECK(U_SUCCESS(*err
));
37 } // namespace l10n_util