@peculiar/fortify-webcomponents
Version:
Web-components for creating CSR or Certificate and viewing certificates list using Fortify
73 lines (72 loc) • 1.99 kB
JavaScript
/*!
* © Peculiar Ventures https://peculiarventures.com/ - BSD 3-Clause License
*/
/**
* @license
* Copyright (c) Peculiar Ventures, LLC.
*
* This source code is licensed under the BSD 3-Clause license found in the
* LICENSE file in the root directory of this source tree.
*/
import en from "../locales/en.json";
import uk from "../locales/uk.json";
import de from "../locales/de.json";
import el from "../locales/el.json";
import it from "../locales/it.json";
import he from "../locales/he.json";
import pl from "../locales/pl.json";
import nl from "../locales/nl.json";
import fr from "../locales/fr.json";
import pt from "../locales/pt.json";
import tr from "../locales/tr.json";
import es from "../locales/es.json";
import ja from "../locales/ja.json";
const MESSAGES_ALL = {
en,
uk,
de,
el,
it,
he,
pl,
nl,
fr,
pt,
tr,
es,
ja,
};
export class Localization {
constructor() {
this.setLocale = (locale) => {
this.locale = locale && MESSAGES_ALL[locale] ? locale : 'en';
this.bundle = MESSAGES_ALL[this.locale];
};
this.getLocale = () => this.locale;
const language = window.navigator.language.slice(0, 2).toLowerCase();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.setLocale(language);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getString(id, replacer) {
const value = this.bundle[id];
if (!value) {
return '';
}
if (!replacer) {
return value;
}
const splitted = value.split(replacer.pattern);
if (splitted.length > 1) {
return [
splitted[0],
replacer.replacer,
splitted[1],
];
}
return value;
}
}
export const l10n = new Localization();
export const getString = l10n.getString.bind(l10n);
//# sourceMappingURL=l10n.js.map