import Ajax from "../components/ajax.js";
class TranslationHelper {
    constructor() {
        this.locale = "es"
        this.lang = {}
    }
    async get_translations(translationFile) {
        return new Promise(async (resolve,reject) => {

            this.locale = $("meta[name='locale']").attr("content");
            this.translationFile = translationFile

            const ajax = new Ajax('/translate/getTranslation',
                {
                    locale: this.locale,
                    translationFile: this.translationFile
                },
                null,
                (response) => {
                    this.lang = JSON.parse(response)
                    resolve(this.lang)
                },
                (error) => {
                    reject(error)
                }
            );
            ajax.post()
        })

    }
    get_lang(key) {
        if (key in this.lang) {
            return this.lang[key]
        }else{
            return key
        }
    }

}

export default TranslationHelper;