"use strict";

var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TranslationUtil = exports.TranslationNamespace = void 0;
const agv_ts_np_en_1 = __importDefault(require("../i18n/agv-ts-np-en"));
const agv_ts_np_ja_1 = __importDefault(require("../i18n/agv-ts-np-ja"));
const agv_ts_np_ko_1 = __importDefault(require("../i18n/agv-ts-np-ko"));
const agv_ts_np_ru_1 = __importDefault(require("../i18n/agv-ts-np-ru"));
const agv_ts_np_zh_CN_1 = __importDefault(require("../i18n/agv-ts-np-zh_CN"));
const agv_ts_np_zh_TW_1 = __importDefault(require("../i18n/agv-ts-np-zh_TW"));
const AGV_RESOURCE_EN = agv_ts_np_en_1.default;
const AGV_RESOURCE_JA = agv_ts_np_ja_1.default;
const AGV_RESOURCE_KO = agv_ts_np_ko_1.default;
const AGV_RESOURCE_RU = agv_ts_np_ru_1.default;
const AGV_RESOURCE_ZH_CN = agv_ts_np_zh_CN_1.default;
const AGV_RESOURCE_ZH_TW = agv_ts_np_zh_TW_1.default;
var TranslationNamespace;
(function (TranslationNamespace) {
  TranslationNamespace["AGV"] = "agv_ts_np";
})(TranslationNamespace || (exports.TranslationNamespace = TranslationNamespace = {}));
class TranslationUtil {
  constructor() {
    this.namespaceResourceMap = {
      [TranslationNamespace.AGV]: AGV_RESOURCE_EN
    };
    this.languageResourceMap = {
      en: {
        [TranslationNamespace.AGV]: AGV_RESOURCE_EN
      },
      ja: {
        [TranslationNamespace.AGV]: AGV_RESOURCE_JA
      },
      ko: {
        [TranslationNamespace.AGV]: AGV_RESOURCE_KO
      },
      ru: {
        [TranslationNamespace.AGV]: AGV_RESOURCE_RU
      },
      zh_CN: {
        [TranslationNamespace.AGV]: AGV_RESOURCE_ZH_CN
      },
      zh_TW: {
        [TranslationNamespace.AGV]: AGV_RESOURCE_ZH_TW
      }
    };
  }
  normalizeLanguage(language = 'en') {
    const lower = String(language || 'en').toLowerCase();
    if (lower === 'zh-cn' || lower === 'zh_cn') {
      return 'zh_CN';
    }
    if (lower === 'zh-tw' || lower === 'zh_tw') {
      return 'zh_TW';
    }
    if (lower.startsWith('zh')) {
      return 'zh_CN';
    }
    if (lower.includes('-') || lower.includes('_')) {
      const base = lower.split(/[-_]/)[0];
      if (base) {
        return base;
      }
    }
    return lower;
  }
  resolveResource(language, namespace) {
    var _a, _b;
    if (!namespace) {
      return null;
    }
    const lang = this.normalizeLanguage(language);
    const nsResource = ((_a = this.languageResourceMap[lang]) === null || _a === void 0 ? void 0 : _a[namespace]) || ((_b = this.languageResourceMap.en) === null || _b === void 0 ? void 0 : _b[namespace]) || this.namespaceResourceMap[namespace] || null;
    return nsResource !== null && nsResource !== void 0 ? nsResource : null;
  }
  escape(value) {
    return value.replace(/&/g, '&amp;');
  }
  toAimLanguage(language, attr, namespace = '') {
    var _a;
    const source = String(attr !== null && attr !== void 0 ? attr : '');
    if (!namespace) {
      return this.escape(source);
    }
    const resource = this.resolveResource(language, namespace);
    return this.escape((_a = resource === null || resource === void 0 ? void 0 : resource[source]) !== null && _a !== void 0 ? _a : source);
  }
  translation(value, language = 'en', namespace = '') {
    var _a;
    const source = String(value !== null && value !== void 0 ? value : '');
    if (!namespace) {
      return this.escape(source);
    }
    const resource = this.resolveResource(language, namespace);
    return this.escape((_a = resource === null || resource === void 0 ? void 0 : resource[source]) !== null && _a !== void 0 ? _a : source);
  }
}
const translationUtil = new TranslationUtil();
exports.TranslationUtil = translationUtil;
exports.default = translationUtil;
//# sourceMappingURL=translation.util.js.map