Cannot format number when Intl polyfill is dynamically loaded
See original GitHub issuevue & vue-i18n version
vue - 2.5.17 vue-i18n - 8.3.2
What is actually happening?
When browser does not support Intl API (for example, Opera 12 or browser on an old Smart TV) and Intl.js polyfill is dynamically loaded via webpack’s require.ensure, vue-i18n does not format numbers because value for VueI18n.availabilities is determined once upon loading of vue-i18n which is included in vendors chunk and loaded before application code where the polyfill is requested. As a result VueI18n.availabilities.dateTimeFormat
and VueI18n.availabilities.numberFormat
are set to false
and _n method always returns empty string.
A possible fix is to define getter for VueI18n.availabilities
:
let availabilities;
Object.defineProperty(VueI18n, 'availabilities', {
get: function get() {
return availabilities || (availabilities = {
dateTimeFormat: typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat !== 'undefined',
numberFormat: typeof Intl !== 'undefined' && typeof Intl.NumberFormat !== 'undefined'
});
}
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Intl.js polyfill/shim with webpack? - javascript
This will create a separate bundle for just the Intl. js file, which will be loaded on an as-needed basis.
Read more >Learn how to add the Internationalization Polyfill to a ...
Once installed in your Angular CLI project go to the /src/polyfills.ts file. In here you can add the following lines. import 'intl'; import ......
Read more >React internationalization with react-intl
Load translations dynamically. Using dynamic imports, we are loading localization messages only when they are needed. Moreover, that way, we are ...
Read more >48 answers on StackOverflow to the most popular Angular ...
zone.js:461 Unhandled Promise rejection: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'.
Read more >Imperative API | Format.JS
There are a few API layers that React Intl provides and is built on. ... React component cannot be used (e.g <img title/>...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@exoego I’m going to make a PR at this weekend.
@kazupon has rewarded $28.00 to @gamtiq. See it on IssueHunt