question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot format number when Intl polyfill is dynamically loaded

See original GitHub issue

vue & 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gamtiqcommented, Dec 14, 2018

@exoego I’m going to make a PR at this weekend.

0reactions
IssueHuntBotcommented, Jan 5, 2019

@kazupon has rewarded $28.00 to @gamtiq. See it on IssueHunt

  • 💰 Total deposit: $40.00
  • 🎉 Repository reward(20%): $8.00
  • 🔧 Service fee(10%): $4.00
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found