"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("@mongosh/errors");
const de_DE_1 = __importDefault(require("./locales/de_DE"));
const en_US_1 = __importDefault(require("./locales/en_US"));
const DEFAULT_LOCALE = 'en_US';
const MAPPINGS = {
    en_US: en_US_1.default,
    de_DE: de_DE_1.default,
};
class Translator {
    __(key) {
        const translation = this.translate(key);
        if (translation === undefined) {
            throw new errors_1.MongoshInternalError(`Could not translate key ${JSON.stringify(key)}`);
        }
        return translation;
    }
    constructor(catalog) {
        this.locale = DEFAULT_LOCALE;
        if (catalog) {
            this.catalog = catalog;
        }
        else {
            this.catalog = MAPPINGS[this.locale];
        }
    }
    setLocale(locale) {
        if (Object.prototype.hasOwnProperty.call(MAPPINGS, locale)) {
            this.locale = locale;
            this.catalog = MAPPINGS[locale];
        }
        else {
            this.locale = DEFAULT_LOCALE;
            this.catalog = MAPPINGS[DEFAULT_LOCALE];
        }
    }
    translate(key) {
        return this.find(key);
    }
    translateApiHelp(key) {
        const value = this.find(key);
        if (!value) {
            return;
        }
        if (typeof value === 'string') {
            return value;
        }
        const { description = '', link = '', example = '', returns = '' } = value;
        return `${description}\n\n${link}\n\n${example}\n\n${returns}`;
    }
    find(key) {
        return key.split('.').reduce((a, b) => {
            return a ? a[b] : undefined;
        }, this.catalog);
    }
}
exports.default = Translator;
//# sourceMappingURL=translator.js.map