@pinuts/bsr-uikit-relaunch
Version:
BSR UI-KIT Relaunch
76 lines (74 loc) • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "Trans", {
enumerable: true,
get: function () {
return _reactI18next.Trans;
}
});
exports.default = exports.addResourceBundleToLibI18n = void 0;
Object.defineProperty(exports, "i18n", {
enumerable: true,
get: function () {
return _i18next.default;
}
});
exports.setLanguage = void 0;
Object.defineProperty(exports, "useTranslation", {
enumerable: true,
get: function () {
return _reactI18next.useTranslation;
}
});
Object.defineProperty(exports, "withTranslation", {
enumerable: true,
get: function () {
return _reactI18next.withTranslation;
}
});
var _i18next = _interopRequireDefault(require("i18next"));
var _reactI18next = require("react-i18next");
var _locales = require("./locales.js");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// import Backend from 'i18next-xhr-backend';
// not like to use this?
// have a look at the Quick start guide
// for passing in lng and translations on init
_i18next.default
// load translation using xhr -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
// learn more: https://github.com/i18next/i18next-xhr-backend
// .use(Backend)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
// pass the i18n instance to react-i18next.
.use(_reactI18next.initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
resources: _locales.resources,
fallbackLng: 'de',
// debug: true,
ns: ['base'],
defaultNS: 'base',
fallbackNS: 'base',
lng: 'de',
interpolation: {
escapeValue: false // not needed for react as it escapes by default
}
});
const addResourceBundleToLibI18n = resources => {
if (resources?.de?.base) {
_i18next.default.addResourceBundle('de', 'base', resources.de.base, true, true);
}
if (resources?.en?.base) {
_i18next.default.addResourceBundle('en', 'base', resources.en.base, true, true);
}
};
exports.addResourceBundleToLibI18n = addResourceBundleToLibI18n;
const setLanguage = language => {
_i18next.default.changeLanguage(language).then(() => {});
};
exports.setLanguage = setLanguage;
var _default = exports.default = _i18next.default;