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

package.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
import i18n from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import { mergeDeepLeft } from "ramda";
import { initReactI18next } from "react-i18next";
import { LIST_FORMATS } from "./constants";
import { listFormatter, lowerCaseDynamicTextFormatter } from "./utils/customFormatters";
import { sentenceCaseProcessor } from "./utils/customPostProcessors";
import { replaceNullValuesWithGetter } from "./utils/utils";
import commonsEn from "../translations/en.json";

// eslint-disable-next-line import/no-mutable-exports
var 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: commonsEn
    }
  };
  var resources = [hostTranslations, commonsTranslations, packageTranslations].reduce(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) || {};
  taxonomies = replaceNullValuesWithGetter(mergeDeepLeft(hostTaxonomies, defaultTaxonomies));
  i18n.use(LanguageDetector).use(initReactI18next).use(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 (LIST_FORMATS.includes(_format)) {
          newValue = listFormatter({
            value: newValue,
            format: _format,
            lng: lng,
            options: options
          });
          return newValue;
        }
        return lowerCaseDynamicTextFormatter(newValue, _format);
      }
    },
    postProcess: [sentenceCaseProcessor.name],
    detection: {
      order: ["querystring", "cookie", "navigator", "path"],
      caches: ["cookie"],
      lookupQuerystring: "lang",
      lookupCookie: "lang"
    }
  });
};
export { taxonomies };
export default initializeI18n;
//# sourceMappingURL=i18n.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy