Bug 1673539 - Multiply by 100 when using style percent in Fluent. r=dminor

Differential Revision: https://phabricator.services.mozilla.com/D94845
This commit is contained in:
Zibi Braniecki 2020-10-29 16:21:54 +00:00
parent 617e00d069
commit 40fc79d8ea
2 changed files with 18 additions and 1 deletions

View File

@ -227,7 +227,8 @@ ffi::RawNumberFormatter* FluentBuiltInNumberFormatterCreate(
MOZ_ASSERT(U_SUCCESS(ec), "Failed to format the currency unit.");
}
if (aOptions->style == ffi::FluentNumberStyleRaw::Percent) {
formatter = formatter.unit(icu::NoUnit::percent());
formatter = formatter.unit(icu::NoUnit::percent())
.scale(icu::number::Scale::powerOfTen(2));
}
if (aOptions->minimum_significant_digits >= 0 ||

View File

@ -4,6 +4,7 @@
function run_test() {
test_methods_presence(FluentBundle);
test_methods_calling(FluentBundle, FluentResource);
test_number_options(FluentBundle, FluentResource);
ok(true);
}
@ -29,3 +30,18 @@ function test_methods_calling(FluentBundle, FluentResource) {
equal(bundle.formatPattern(msg2.value, { name: "Amy" }), "Hello Amy");
ok(true);
}
function test_number_options(FluentBundle, FluentResource) {
const bundle = new FluentBundle(["en-US", "pl"], {
useIsolating: false,
});
bundle.addResource(new FluentResource(`
key = { NUMBER(0.53, style: "percent") } { NUMBER(0.12, style: "percent", minimumFractionDigits: 0) }
{ NUMBER(-2.5, style: "percent") } { NUMBER(2.91, style: "percent") } { NUMBER("wrong", style: "percent") }
`));
const msg = bundle.getMessage("key");
equal(bundle.formatPattern(msg.value), "53.00% 12%\n-250.0% 291.00% ");
ok(true);
}