I've noticed that en-FR
does not appear to be a fully supported locale by the Intl.NumberFormat
API.
I've not found any official list of supported locales by the Intl
api. However, I can assume the list from a fairly popular polyfill by formatjs
That list of supported locales does not include en-FR
. Maybe I'm being naive but I think this locale would be a commonly supported locale, for example for users who speak English but are in a French region.
const numberFormatter = Intl.NumberFormat('en-FR');
//numberFormatter.resolvedOptions()
{
"locale": "en",
"numberingSystem": "latn",
"style": "decimal",
"minimumIntegerDigits": 1,
"minimumFractionDigits": 0,
"maximumFractionDigits": 3,
"useGrouping": "auto",
"notation": "standard",
"signDisplay": "auto",
"roundingMode": "halfExpand",
"roundingIncrement": 1,
"trailingZeroDisplay": "auto",
"roundingPriority": "auto"
}
//numberFormatter.formatToParts(1234.56)
1,234.56
When a new Intl.NumberFormat
is contrusted with the en-FR
locale, it appears to fallback to just a en
locale. This is problematic as the en
locale will produce a different number format than an en-FR
locale would:
Locale | Input | Expected Output |
---|---|---|
en-FR |
12345.56 | 1 234,56 |
en |
12345.56 | 1,2345.56 |
Is there any way to control the decimal
or group
characters of the Intl.NumberFormat
API? Or is there any way to add a custom locale support?
The use case stems from the iOS ecosystem, where a user may have a language of locale en-GB
, but a region setting of en-FR
. The numbers, dates, currencies should reflect the "France" region, but the actual translations should reflect the "English (United Kingdom)" language.