Added ability to override UI labels

This commit is contained in:
Rainer Simon 2021-04-18 13:09:56 +02:00
parent 6ec1995791
commit 6895f39660
2 changed files with 10 additions and 5 deletions

View File

@ -3,9 +3,14 @@ import * as timeago from 'timeago.js';
const i18n = new Polyglot({ allowMissing: true });
i18n.init = lang => {
i18n.locale(lang);
i18n.extend(require(`./messages_${lang}.json`));
i18n.init = (lang, opt_messages) => {
if (lang) {
i18n.locale(lang);
i18n.extend(require(`./messages_${lang}.json`));
}
if (opt_messages)
i18n.extend(opt_messages);
}
/** Load and register TimeAgo locales **/

View File

@ -27,13 +27,13 @@ export const addPolyfills = () => {
/**
* Helper to init the i18n class with a pre-defined or auto-detected locale.
*/
export const setLocale = locale => {
export const setLocale = (locale, opt_messages) => {
if (locale) {
const l = locale === 'auto' ?
window.navigator.userLanguage || window.navigator.language : locale;
try {
I18n.init(l.split('-')[0].toLowerCase());
I18n.init(l.split('-')[0].toLowerCase(), opt_messages);
} catch (error) {
console.warn(`Unsupported locale '${l}'. Falling back to default en.`);
}