UNPKG

terra-i18n

Version:

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

43 lines (41 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _translationsLoaders = _interopRequireDefault(require("translationsLoaders")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* eslint-disable import/no-unresolved, no-console */ var loadFallbackLocale = function loadFallbackLocale(localeContext, callback, scope) { try { _translationsLoaders.default.en(callback, scope); if (process.env.NODE_ENV !== 'production') { console.warn("Translations were not supplied for the ".concat(localeContext, ". Using en as the fallback locale.")); } } catch (e) { throw new Error("Translations were not supplied for the ".concat(localeContext, ", or the en fallback locale.")); } }; var loadTranslations = function loadTranslations(locale, callback, scope) { var fallbackLocale = locale.split('-').length > 1 ? locale.split('-')[0] : false; try { _translationsLoaders.default[locale](callback, scope); } catch (e) { if (fallbackLocale) { try { _translationsLoaders.default[fallbackLocale](callback, scope); if (process.env.NODE_ENV !== 'production') { console.warn("Translations were not supplied for the ".concat(locale, " locale. Using ").concat(fallbackLocale, " as the fallback locale.")); } } catch (error) { var localeContext = "".concat(locale, " or ").concat(fallbackLocale, " locales"); loadFallbackLocale(localeContext, callback, scope); } } else { var _localeContext = "".concat(locale, " locale"); loadFallbackLocale(_localeContext, callback, scope); } } }; var _default = exports.default = loadTranslations; /* eslint-enable import/no-unresolved, no-console */