UNPKG

@gez/date-time-kit

Version:

42 lines (41 loc) 1.62 kB
var __freeze = Object.freeze; var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) })); var _a, _b; import i18n, { langs } from "../../i18n.mjs"; import { UiBase } from "../web-component-base/index.mjs"; import { css, html } from "../../utils/index.mjs"; export class Ele extends UiBase { static get observedAttributes() { return [ ...super.observedAttributes, "i18n-key" ]; } _onAttrChanged(name, oldValue, newValue) { super._onAttrChanged(name, oldValue, newValue); if (name === "lang" || name === "i18n-key") this.updateText(); } connectedCallback() { if (!super.connectedCallback()) return; this.updateText(); } updateText() { let lang = this._getAttr("lang", "en-US"); if (!langs.includes(lang)) lang = "en-US"; let text = i18n[lang]; const keys = (this._getAttr("i18n-key") || "").split("."); for (const k of keys) { text = text == null ? void 0 : text[k]; if (!text) break; } if (text) this.textContent = text; } } __publicField(Ele, "tagName", "dt-i18n"); __publicField(Ele, "_style", css(_a || (_a = __template([":host{display:contents}"])))); __publicField(Ele, "_template", html(_b || (_b = __template(["<slot></slot>"])))); Ele.define();