All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.cjs.initializers.i18n.js Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
"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 = {};
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 = exports["default"] = initializeI18n;
//# sourceMappingURL=i18n.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy