@vaadin/hilla-react-i18n
Version:
Hilla I18n utils for React
21 lines • 621 B
JavaScript
import { IntlMessageFormat } from "intl-messageformat";
export class FormatCache {
#language;
#formats = new Map();
constructor(language) {
let supportedLocales = [];
try {
supportedLocales = Intl.NumberFormat.supportedLocalesOf(language);
} catch {}
this.#language = supportedLocales.length > 0 ? supportedLocales[0] : navigator.language;
}
getFormat(translation) {
let format = this.#formats.get(translation);
if (!format) {
format = new IntlMessageFormat(translation, this.#language);
this.#formats.set(translation, format);
}
return format;
}
}
//# sourceMappingURL=./FormatCache.js.map