Added ability to override UI labels
This commit is contained in:
parent
6ec1995791
commit
6895f39660
|
@ -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 **/
|
||||
|
|
|
@ -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.`);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue