Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No locale data has been provided" regardless of what is passed in

I am trying to use intl to do some formatting but no matter what I pass in as the locale, I always get the following error message:

ReferenceError: No locale data has been provided for this object yet

I have tried the following:

new Intl.NumberFormat('en-ZA', { minimumFractionDigits: percentDecimals });

as well as

new Intl.NumberFormat(['en-ZA'], { minimumFractionDigits: percentDecimals });

and I am not sure what else do.

I have added the package to the package.json

"intl": "latest"

and I do import it

import Intl from "intl";
like image 364
David Pilkington Avatar asked Jun 13 '17 08:06

David Pilkington


1 Answers

Depending on the enviromnent you are running this code you might need to import locale data as well to polyfill locale

import 'intl/locale-data/jsonp/en-ZA'

This import does side-effect that register en-ZA locale IntlPolyfill.__addLocaleData({locale:"en-ZA", when polyfill is required.

like image 167
Yury Tarabanko Avatar answered Nov 06 '22 22:11

Yury Tarabanko