kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js
https://kazupon.github.io/vue-i18n/
MIT License
7.26k stars 861 forks source link

TypeError: formatter.formatToParts is not a function in older browsers #922

Open alexcroox opened 4 years ago

alexcroox commented 4 years ago

vue & vue-i18n version

"vue-i18n": "^8.18.1", "vue": "^2.6.11",

Older browsers such as Chrome 50 are erroring with: TypeError: formatter.formatToParts is not a function

Which relates to VueI18n.prototype._ntp

var formatter = this._getNumberFormatter(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options);
var ret = formatter && formatter.formatToParts(value);

Is there anything specific I can do to pollyfill this? I've tried adding:

transpileDependencies: ['vue-i18n'] with no joy

alexcroox commented 4 years ago

I've just done some more digging, Intl: NumberFormat: formatToParts has no pollyfills. So this library won't work with IE11 or iOS 11 or iOS 12 if you want to use i18n-n

https://caniuse.com/#feat=mdn-javascript_builtins_intl_numberformat_formattoparts

exoego commented 4 years ago

Oops... IE11 is one of supported browser of vue-i18n (ref. #843, #844), so this is definitely bug. formatter.formatToParts should be replaced with polyfill.

alexcroox commented 4 years ago

I don't believe there is one for formatToParts.

exoego commented 4 years ago

According to MDN, a github repository https://github.com/tc39/proposal-intl-formatToParts provides polyfill for formatToParts. PRs are welcome.

alexcroox commented 4 years ago

Sorry I wasn't clear, see this issue from that repo: https://github.com/tc39/proposal-intl-formatToParts/issues/4

Current polyfill contains only Intl.DateTimeFormat.prototype.formatToParts but not Intl.NumberFormat.prototype.formatToParts