"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.setupI18n = void 0;

var _core = require("@lingui/core");

var plurals = _interopRequireWildcard(require("make-plural/plurals"));

var _logger = require("../logger");

var _globalSettings = require("../repository/globalSettings");

var _translation = require("./locales/da/translation");

var _translation2 = require("./locales/de/translation");

var _translation3 = require("./locales/en/translation");

var _translation4 = require("./locales/es/translation");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const setupI18n = locale => {
  _core.i18n.loadLocaleData({
    da: {
      plurals: plurals.da
    },
    de: {
      plurals: plurals.de
    },
    en: {
      plurals: plurals.en
    },
    es: {
      plurals: plurals.es
    }
  });

  _core.i18n.load({
    da: _translation.messages,
    de: _translation2.messages,
    en: _translation3.messages,
    es: _translation4.messages
  });

  _core.i18n.activate(locale);

  _globalSettings.GlobalConfiguration.subscribe('serverLang', lng => {
    if (_core.i18n.locale === lng || !lng) {
      return;
    }

    _logger.logger.info(
    /*i18n*/
    _core.i18n._("Changing server language to {lng}", {
      lng: lng
    }));

    _core.i18n.activate(lng);
  });
};

exports.setupI18n = setupI18n;
//# sourceMappingURL=i18n.js.map