UNPKG

@larva.io/webcomponents

Version:

Fentrica SmartUnits WebComponents package

92 lines (89 loc) 2.83 kB
/*! * (C) Fentrica http://fentrica.com - Seee LICENSE.md */ import { p as proxyCustomElement, H, c as createEvent } from './p-AOwgnAK2.js'; import { i as i18n } from './p-Cga1x4Z-.js'; const LarvaTranslate = /*@__PURE__*/ proxyCustomElement(class LarvaTranslate extends H { constructor(registerHost) { super(); if (registerHost !== false) { this.__registerHost(); } this.larlangchange = createEvent(this, "larlangchange"); this.i18n = i18n; // input text this.t = ''; // translated (text this.tt = ''; } changeHandler() { try { const exists = this.i18n.exists(this.t, { lng: this.i18n.language }); const fallback = this.fallback ? this.fallback : this.t; this.tt = exists ? this.i18n.t(this.t, { lng: this.i18n.language }) : fallback; } catch (err) { console.error(this.t); console.error(err); } } componentWillLoad() { this.changeHandler(); this.bindedListener = () => { this.larlangchange.emit(); this.changeHandler(); }; this.i18n.on('languageChanged', this.bindedListener); this.i18n.on('languagechanged', this.bindedListener); } disconnectedCallback() { try { this.i18n.off('languageChanged', this.bindedListener); this.i18n.off('languagechanged', this.bindedListener); } catch (err) { console.error(err); } } fillTranslationValues(translation = '', values) { if (!values) { return translation; } return translation.replace(/{\w+}/g, (key) => { const parsedKey = key.substring(1, key.length - 1); return (values[parsedKey] || 'undefined').toString(); }); } render() { return this.fillTranslationValues(this.tt, this.values); } get el() { return this; } static get watchers() { return { "t": ["changeHandler"] }; } }, [256, "lar-translate", { "values": [8], "t": [1], "fallback": [1], "tt": [32], "bindedListener": [32] }, undefined, { "t": ["changeHandler"] }]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["lar-translate"]; components.forEach(tagName => { switch (tagName) { case "lar-translate": if (!customElements.get(tagName)) { customElements.define(tagName, LarvaTranslate); } break; } }); } defineCustomElement(); export { LarvaTranslate as L, defineCustomElement as d }; //# sourceMappingURL=p-B-fmI6sr.js.map //# sourceMappingURL=p-B-fmI6sr.js.map