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