package.cjs.initializers.i18n.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.taxonomies = exports["default"] = void 0;
var _i18next = _interopRequireDefault(require("i18next"));
var _i18nextBrowserLanguagedetector = _interopRequireDefault(require("i18next-browser-languagedetector"));
var _ramda = require("ramda");
var _reactI18next = require("react-i18next");
var _constants = require("./constants");
var _customFormatters = require("./utils/customFormatters");
var _customPostProcessors = require("./utils/customPostProcessors");
var _utils = require("./utils/utils");
var _en = _interopRequireDefault(require("../translations/en.json"));
// eslint-disable-next-line import/no-mutable-exports
var taxonomies = {};
exports.taxonomies = taxonomies;
var initializeI18n = function initializeI18n(hostTranslations) {
var _window$globalProps;
// eslint-disable-next-line no-undef
var packageTranslations = preval.require("../configs/scripts/getPkgTranslations.js");
var commonsTranslations = {
en: {
translation: _en["default"]
}
};
var resources = [hostTranslations, commonsTranslations, packageTranslations].reduce(_ramda.mergeDeepLeft);
var defaultTaxonomyKeys = Object.keys(resources.en.translation.taxonomyDefaultLabels || {});
var defaultTaxonomies = Object.fromEntries(defaultTaxonomyKeys.map(function (key) {
return [key, {
singular: null,
plural: null
}];
}));
var hostTaxonomies = ((_window$globalProps = window.globalProps) === null || _window$globalProps === void 0 ? void 0 : _window$globalProps.taxonomies) || {};
exports.taxonomies = taxonomies = (0, _utils.replaceNullValuesWithGetter)((0, _ramda.mergeDeepLeft)(hostTaxonomies, defaultTaxonomies));
_i18next["default"].use(_i18nextBrowserLanguagedetector["default"]).use(_reactI18next.initReactI18next).use(_customPostProcessors.sentenceCaseProcessor).init({
resources: resources,
fallbackLng: "en",
interpolation: {
defaultVariables: {
taxonomies: taxonomies
},
escapeValue: false,
skipOnVariables: false,
alwaysFormat: true,
format: function format(value, _format, lng, options) {
var newValue = value;
if (_constants.LIST_FORMATS.includes(_format)) {
newValue = (0, _customFormatters.listFormatter)({
value: newValue,
format: _format,
lng: lng,
options: options
});
return newValue;
}
return (0, _customFormatters.lowerCaseDynamicTextFormatter)(newValue, _format);
}
},
postProcess: [_customPostProcessors.sentenceCaseProcessor.name],
detection: {
order: ["querystring", "cookie", "navigator", "path"],
caches: ["cookie"],
lookupQuerystring: "lang",
lookupCookie: "lang"
}
});
};
var _default = initializeI18n;
exports["default"] = _default;
//# sourceMappingURL=i18n.js.map