Vulcan/packages/vulcan-lib/lib/server/intl_polyfill.js

29 lines
833 B
JavaScript
Raw Permalink Normal View History

2017-06-01 11:49:32 +09:00
/*
intl polyfill. See https://github.com/andyearnshaw/Intl.js/
*/
import { getSetting, registerSetting } from '../modules/settings.js';
registerSetting('locale', 'en');
2017-06-01 11:49:32 +09:00
var areIntlLocalesSupported = require('intl-locales-supported');
var localesMyAppSupports = [
getSetting('locale', 'en')
2017-06-01 11:49:32 +09:00
];
if (global.Intl) {
// Determine if the built-in `Intl` has the locale data we need.
if (!areIntlLocalesSupported(localesMyAppSupports)) {
// `Intl` exists, but it doesn't have the data we need, so load the
// polyfill and replace the constructors with need with the polyfill's.
var IntlPolyfill = require('intl');
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
}
} else {
// No `Intl`, so use and load the polyfill.
global.Intl = require('intl');
}