Open Bug 1673545 Opened 4 years ago Updated 2 years ago

Support NumberFormat rev. 2 in Fluent

Categories

(Core :: Internationalization: Localization, defect)

defect

Tracking

()

People

(Reporter: flod, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: good-first-bug, helpwanted)

NUMBER(100, signDisplay: "always")
NUMBER(-99, signDisplay: "never")

In Firefox this will display 100 and -99, while on Fluent's playground it will display correctly +100 and 99.

Also getting correctly +100 in Console with

new Intl.NumberFormat("en-US", {    
    signDisplay: "always"
}).format([100]);
Component: Internationalization → Internationalization: Localization

We should extend this bug to cover other features supported by Unified Number Format (NumberFormat rev. 2) proposal https://github.com/tc39/proposal-unified-intl-numberformat

The functionality is there, but in some cases the operations between C++ and options bag are not trivial, and we should closely follow what SpiderMonkey is doing here https://searchfox.org/mozilla-central/source/js/src/builtin/intl/NumberFormat.cpp#496

Summary: Fluent NUMBER() function: signDisplay style is ignored → Support NumberFormat rev. 2 in Fluent
Depends on: 1695937
No longer depends on: 1686965

With bug 1695937 fixed, Gecko can now handle NumberFormat rev. 2!

What's left is to add support for it into fluent-rs. NumberFormat is this weird outlier for now, since it is defined in fluent-rs itself because we do need to format numbers (compared to DateTime which is a CustomType and doesn't exist in fluent-rs itself), even in a quasi way.

Eventually, I expect fluent-bundle to just depend on icu_number which should handle it well, but for now, we will have to:

  1. Extend https://github.com/projectfluent/fluent-rs/blob/master/fluent-bundle/src/types/number.rs#L60 to pass through all new options from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
  2. Extend https://searchfox.org/mozilla-central/source/intl/l10n/rust/fluent-ffi/src/ffi.rs#49 to match it
  3. Extend https://searchfox.org/mozilla-central/source/intl/l10n/FluentBundle.cpp#212 to match it

That should do it.

In theory we could try to make mozilla::intl::NumberFormatOptions accessible from Rust so that we could remove NumberFormatOptionsRaw and just construct the m::i::NumberFormatOptions from fluent::types::NumberFormatOptions, but I'm not sure if that type will work well as exposed to Rust.

:dminor - what do you think?

Flags: needinfo?(dminor)

I think everything in mozilla::intl::NumberFormatOptions has a natural rust representation, but I think we'd have to write manual wrappers to get it working. I spent a little bit of time with bindgen this morning, and it was not generating anything sensible for mozilla::Maybe. I don't think it's worth investing in writing manual wrappers when we eventually plan to just call into icu_number directly, so your steps 1 - 3 make good sense to me.

Flags: needinfo?(dminor)
Assignee: nobody → gtatum

This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit auto_nag documentation.

Assignee: gtatum → nobody
Severity: -- → S3
You need to log in before you can comment on or make changes to this bug.