diff --git a/crabfit-frontend/src/components/Settings/Settings.tsx b/crabfit-frontend/src/components/Settings/Settings.tsx index 453be18..c8c7308 100644 --- a/crabfit-frontend/src/components/Settings/Settings.tsx +++ b/crabfit-frontend/src/components/Settings/Settings.tsx @@ -16,6 +16,14 @@ import { 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 theme = useTheme(); const store = useSettingsStore(); @@ -36,12 +44,13 @@ const Settings = () => { } }, [i18n.language, setLocale]); + if (!i18n.options.storedLang) { + setDefaults(i18n.language, store); + i18n.options.storedLang = i18n.language; + } + i18n.on('languageChanged', lang => { - // Language specific options - if (locales.hasOwnProperty(lang)) { - store.setWeekStart(locales[lang].weekStart); - store.setTimeFormat(locales[lang].timeFormat); - } + setDefaults(lang, store); }); return ( diff --git a/crabfit-frontend/src/i18n/index.ts b/crabfit-frontend/src/i18n/index.ts index 82c582c..433fedf 100644 --- a/crabfit-frontend/src/i18n/index.ts +++ b/crabfit-frontend/src/i18n/index.ts @@ -5,6 +5,8 @@ import Backend from 'i18next-http-backend'; import locales from 'res/dayjs_locales'; +const storedLang = localStorage.getItem('i18nextLng'); + i18n .use(LanguageDetector) .use(Backend) @@ -21,6 +23,7 @@ i18n backend: { loadPath: '/i18n/{{lng}}/{{ns}}.json', }, + storedLang, }).then(() => document.documentElement.setAttribute('lang', i18n.language)); export default i18n;