71 lines
2.6 KiB
JavaScript
71 lines
2.6 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.warnOnce = exports.warn = exports.loadNamespaces = exports.loadLanguages = exports.isString = exports.isObject = exports.hasLoadedNamespace = exports.getDisplayName = void 0;
|
|
const warn = function () {
|
|
if (console?.warn) {
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
if (isString(args[0])) args[0] = `react-i18next:: ${args[0]}`;
|
|
console.warn(...args);
|
|
}
|
|
};
|
|
exports.warn = warn;
|
|
const alreadyWarned = {};
|
|
const warnOnce = function () {
|
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
args[_key2] = arguments[_key2];
|
|
}
|
|
if (isString(args[0]) && alreadyWarned[args[0]]) return;
|
|
if (isString(args[0])) alreadyWarned[args[0]] = new Date();
|
|
warn(...args);
|
|
};
|
|
exports.warnOnce = warnOnce;
|
|
const loadedClb = (i18n, cb) => () => {
|
|
if (i18n.isInitialized) {
|
|
cb();
|
|
} else {
|
|
const initialized = () => {
|
|
setTimeout(() => {
|
|
i18n.off('initialized', initialized);
|
|
}, 0);
|
|
cb();
|
|
};
|
|
i18n.on('initialized', initialized);
|
|
}
|
|
};
|
|
const loadNamespaces = (i18n, ns, cb) => {
|
|
i18n.loadNamespaces(ns, loadedClb(i18n, cb));
|
|
};
|
|
exports.loadNamespaces = loadNamespaces;
|
|
const loadLanguages = (i18n, lng, ns, cb) => {
|
|
if (isString(ns)) ns = [ns];
|
|
ns.forEach(n => {
|
|
if (i18n.options.ns.indexOf(n) < 0) i18n.options.ns.push(n);
|
|
});
|
|
i18n.loadLanguages(lng, loadedClb(i18n, cb));
|
|
};
|
|
exports.loadLanguages = loadLanguages;
|
|
const hasLoadedNamespace = function (ns, i18n) {
|
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
if (!i18n.languages || !i18n.languages.length) {
|
|
warnOnce('i18n.languages were undefined or empty', i18n.languages);
|
|
return true;
|
|
}
|
|
return i18n.hasLoadedNamespace(ns, {
|
|
lng: options.lng,
|
|
precheck: (i18nInstance, loadNotPending) => {
|
|
if (options.bindI18n?.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
|
|
}
|
|
});
|
|
};
|
|
exports.hasLoadedNamespace = hasLoadedNamespace;
|
|
const getDisplayName = Component => Component.displayName || Component.name || (isString(Component) && Component.length > 0 ? Component : 'Unknown');
|
|
exports.getDisplayName = getDisplayName;
|
|
const isString = obj => typeof obj === 'string';
|
|
exports.isString = isString;
|
|
const isObject = obj => typeof obj === 'object' && obj !== null;
|
|
exports.isObject = isObject; |