globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 605 forks source link

support formatted ranges of numbers #562

Open patch opened 8 years ago

patch commented 8 years ago

CLDR supports range patterns under miscPatterns and are very useful for formatting ranges of numbers (e.g. 5–10), with each number formatted appropriately as well as the range itself.

http://unicode.org/reports/tr35/tr35-numbers.html#Miscellaneous_Patterns

rxaviers commented 8 years ago

As a first step, let's get an API drafted possibly by benchmarking existing implementations.

patch commented 8 years ago

Here are the Perl CLDR::Number range docs and tests. Note that I implemented it for numbers, percents, and prices, but it's only explicitly defined in UTS #35 for numbers. I chatted with Mark Davis about this at IUC39 and am going to propose standardizing and documenting ranges of percents and prices to the CLDR-TC. For the number ranges at least, the current specification is stable.

rxaviers commented 8 years ago

:+1:

patch commented 8 years ago

See also the atLeast pattern, which is the only other pattern in miscPatterns, so it would make sense to draft the API with both in mind. I don't personally use it, but implemented it as at_least in CLDR::Number. (More unit tests for both of these: https://github.com/patch/cldr-number-pm5/blob/master/t/from-uts35.t#L50-L53)