maplair
Version:
JavaScript library for mobile-friendly interactive maps
36 lines (35 loc) • 906 B
JavaScript
import { template } from "./Util.js";
//#region src/core/I18n.js
var I18n = class {
static #messages = {};
static #locale = null;
static registerLocale(locale, messages) {
this.#messages[locale] = {
...this.#messages[locale],
...messages
};
}
static setLocale(locale) {
this.#locale = locale;
}
static getLocale() {
return this.#locale;
}
static translate(string, data = {}) {
if (this.#locale === null) return template(string, data);
const translation = this.#messages[this.#locale]?.[string];
if (!translation) {
console.warn(`No translation found for "${string}", falling back to the original string.`);
return template(string, data);
}
try {
return template(translation, data);
} catch (err) {
console.error(`Error while translating "${translation}".`, err);
return translation;
}
}
};
//#endregion
export { I18n };
//# sourceMappingURL=I18n.js.map