UNPKG

terra-i18n

Version:

The terra-i18n package provides on-demand internationalization of React components.

52 lines (49 loc) 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _intlLoaders = _interopRequireDefault(require("./intlLoaders")); var _translationsLoaders = _interopRequireDefault(require("./translationsLoaders")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } /* eslint-disable global-require, import/no-named-as-default */ var permitParams = function permitParams(callback) { if (typeof callback !== 'function') { throw new Error('Second argument must be function'); } }; var _default = exports.default = function _default(locale, callback, scope) { permitParams(callback); /** * Use try-catch to check if Intl is provided by the browser. In some instances checking Intl will throw an * error and crash the page with little information. * * Reference: https://github.com/cerner/terra-core/issues/2820 */ var hasIntl; try { // eslint-disable-next-line compat/compat hasIntl = (typeof Intl === "undefined" ? "undefined" : _typeof(Intl)) === 'object' && typeof Intl.DateTimeFormat === 'function' && typeof Intl.NumberFormat === 'function'; } catch (error) { hasIntl = false; } if (!hasIntl) { require('intl'); } if (global.IntlPolyfill) { /** * Intl polyfill attempts to cache and restore static RegExp properties before executing any regular expressions in order * to comply with ECMA-402. There are times this results in regex syntax error so we are disabling this feature. * * Reference: https://github.com/andyearnshaw/Intl.js#regexp-cache--restore */ /* eslint-disable no-underscore-dangle */ if (Intl.__disableRegExpRestore && typeof Intl.__disableRegExpRestore === 'function') { Intl.__disableRegExpRestore(); } /* eslint-enable no-underscore-dangle */ (0, _intlLoaders.default)(locale); } (0, _translationsLoaders.default)(locale, callback, scope); }; /* eslint-enable global-require, import/no-named-as-default */