Set language defaults on initial load
This commit is contained in:
parent
615f316be2
commit
2f23fcfd32
|
|
@ -16,6 +16,14 @@ import {
|
||||||
|
|
||||||
import locales from 'res/dayjs_locales';
|
import locales from 'res/dayjs_locales';
|
||||||
|
|
||||||
|
// Language specific options
|
||||||
|
const setDefaults = (lang, store) => {
|
||||||
|
if (locales.hasOwnProperty(lang)) {
|
||||||
|
store.setWeekStart(locales[lang].weekStart);
|
||||||
|
store.setTimeFormat(locales[lang].timeFormat);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const store = useSettingsStore();
|
const store = useSettingsStore();
|
||||||
|
|
@ -36,12 +44,13 @@ const Settings = () => {
|
||||||
}
|
}
|
||||||
}, [i18n.language, setLocale]);
|
}, [i18n.language, setLocale]);
|
||||||
|
|
||||||
i18n.on('languageChanged', lang => {
|
if (!i18n.options.storedLang) {
|
||||||
// Language specific options
|
setDefaults(i18n.language, store);
|
||||||
if (locales.hasOwnProperty(lang)) {
|
i18n.options.storedLang = i18n.language;
|
||||||
store.setWeekStart(locales[lang].weekStart);
|
|
||||||
store.setTimeFormat(locales[lang].timeFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i18n.on('languageChanged', lang => {
|
||||||
|
setDefaults(lang, store);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import Backend from 'i18next-http-backend';
|
||||||
|
|
||||||
import locales from 'res/dayjs_locales';
|
import locales from 'res/dayjs_locales';
|
||||||
|
|
||||||
|
const storedLang = localStorage.getItem('i18nextLng');
|
||||||
|
|
||||||
i18n
|
i18n
|
||||||
.use(LanguageDetector)
|
.use(LanguageDetector)
|
||||||
.use(Backend)
|
.use(Backend)
|
||||||
|
|
@ -21,6 +23,7 @@ i18n
|
||||||
backend: {
|
backend: {
|
||||||
loadPath: '/i18n/{{lng}}/{{ns}}.json',
|
loadPath: '/i18n/{{lng}}/{{ns}}.json',
|
||||||
},
|
},
|
||||||
|
storedLang,
|
||||||
}).then(() => document.documentElement.setAttribute('lang', i18n.language));
|
}).then(() => document.documentElement.setAttribute('lang', i18n.language));
|
||||||
|
|
||||||
export default i18n;
|
export default i18n;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue