UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

117 lines (116 loc) 2.35 kB
import e from "./en-US.js"; import t from "./zh-CN.js"; import n from "./nl-NL.js"; import r from "./fr-FR.js"; import i from "./de-DE.js"; import a from "./it-IT.js"; import o from "./ja-JP.js"; import s from "./pt-BR.js"; import c from "./ru-RU.js"; import l from "./es-LA.js"; import { LocaleManager as u, RawBundleSource as d } from "@dialpad/i18n"; //#region localization/index.js var f = "dialtone", p = { ENGLISH: "en-US", CHINESE: "zh-CN", DUTCH: "nl-NL", FRENCH: "fr-FR", GERMAN: "de-DE", ITALIAN: "it-IT", JAPANESE: "ja-JP", PORTUGUESE: "pt-BR", RUSSIAN: "ru-RU", SPANISH: "es-LA" }, m = "en-US", h = "user-locale", g = class g { constructor(_ = null) { if (typeof g.instance == "object") return g.instance; this._locale = _ || g.getPreferredLocale(); let v = new u({ bundleSource: new d({ resources: d.builtResources([ [ "en-US", f, e ], [ "zh-CN", f, t ], [ "nl-NL", f, n ], [ "fr-FR", f, r ], [ "de-DE", f, i ], [ "it-IT", f, a ], [ "ja-JP", f, o ], [ "pt-BR", f, s ], [ "ru-RU", f, c ], [ "es-LA", f, l ] ]) }), allowedLocales: Object.values(p), fallbackLocale: m, preferredLocale: this._locale, namespaces: [f] }); return g.instance = this, this.i18n = v.useI18N(f), typeof window < "u" && (window.onstorage = (e) => { e.key === h && (this.currentLocale = e.newValue); }), this; } static getPreferredLocale() { if (typeof window > "u" || !window.localStorage) return m; let e = window.localStorage.getItem(h), t = Object.values(p).find((e) => e.startsWith(navigator.language.slice(0, 2))); return e || t || m; } static getAllowedLocales() { return p; } $t(...e) { return this.i18n.$t(...e); } $ta(...e) { return this.i18n.$ta(...e); } get currentLocale() { return this._locale; } set currentLocale(e) { if (e !== this._locale) { if (!Object.values(p).includes(e)) throw Error(`Locale ${e} is not allowed, please use one of the following: ${Object.values(p).join(", ")}`); this._locale = e, this.i18n.setI18N({ preferredLocale: e }, f); } } }; //#endregion export { g as DialtoneLocalization }; //# sourceMappingURL=index.js.map