fluent.js icon indicating copy to clipboard operation
fluent.js copied to clipboard

Support range versions of NUMBER and DATETIME as default builtins

Open angryzor opened this issue 2 years ago • 4 comments

The JavaScript Intl API supports formatRange on both Intl.DateTimeFormat and Intl.NumberFormat. As far as I know these methods are not represented in the builtin functions in fluent.js. Would it be possible to add support for these?

I'm willing to try to make a pull request but I'd like to know the maintainers' stance on this first.

angryzor avatar Sep 06 '22 07:09 angryzor

It would probably make more sense for date and time ranges to be represented by their own FluentType implementations rather than extending FluentNumber and FluentDateTime. Correspondingly, the functions for generating them should probably be separate from NUMBER() and DATETIME(), even though they may internally use the same Intl formatters.

It should be possible for you to build and use all of that via the functions option of the FluentBundle constructor, rather than needing to extend the default builtins. If you do so and make the functions available as an npm package, we'd be happy to link to it from here.

eemeli avatar Sep 06 '22 11:09 eemeli

Makes sense. This is more or less what I had done now in my application, so I'll try to wrap it up in a package.

angryzor avatar Sep 06 '22 16:09 angryzor

Hello @eemeli . I finally got around to bundling my solution up properly, so here is the link: https://github.com/angryzor/fluent-ranges

angryzor avatar Nov 03 '22 17:11 angryzor

@angryzor That looks pretty great! We should take a closer look at this once number range formatting is a bit more widely supported.

eemeli avatar Nov 08 '22 23:11 eemeli