'use strict';

const ASSETS_FOLDER = "gx-ide-assets/";
const COMPONENT_PREFIX = "gx-ide-";
const DEFAULT_LANGUAGE = "en";
const LANGS_FOLDER = "langs/";
const LANG_PREFIX = ".lang.";
const LANG_EXTENSION = ".json";
class Locale {
    static getLang() {
        var _a, _b;
        const lang = (_b = (_a = document
            .getElementsByTagName("html")[0]
            .getAttribute("lang")) === null || _a === void 0 ? void 0 : _a.valueOf()) !== null && _b !== void 0 ? _b : DEFAULT_LANGUAGE;
        // Normalize en-US
        return lang === "en-US" ? "en" : lang;
    }
    static getStrings(component, lang, folder) {
        if (folder === "") {
            folder = `${component}/`;
        }
        const path = `${ASSETS_FOLDER}${folder}${LANGS_FOLDER}${component}${LANG_PREFIX}${lang}${LANG_EXTENSION}`;
        return new Promise((resolve, reject) => {
            fetch(path).then(langFile => {
                if (langFile.ok) {
                    resolve(langFile.json());
                }
                else {
                    reject();
                }
            }, reject);
        });
    }
    static async getComponentStrings(element, folder = "", component = "") {
        if (component === "") {
            component = element.tagName.toLowerCase().replace(COMPONENT_PREFIX, "");
        }
        const lang = Locale.getLang();
        return await Locale.getStrings(component, lang, folder);
    }
    static format(text, parms) {
        let ret = text;
        parms.forEach(parm => {
            ret = ret.replace(`{${parms.indexOf(parm)}}`, parm);
        });
        return ret;
    }
}
Locale.commonAssetsPath = "";

exports.Locale = Locale;

//# sourceMappingURL=locale-ff30a5f3.js.map