1
0

feat(user): use user language from store after logging in

This commit is contained in:
kolaente
2023-06-12 16:08:31 +02:00
parent 5325f6d7d9
commit 68597c9709
3 changed files with 13 additions and 12 deletions

View File

@ -1,5 +1,6 @@
import {createI18n} from 'vue-i18n'
import langEN from './lang/en.json'
import {useAuthStore} from '@/stores/auth'
export const SUPPORTED_LOCALES = {
'en': 'English',
@ -54,9 +55,14 @@ export async function setLanguage(lang: SupportedLocale = getCurrentLanguage()):
}
export function getCurrentLanguage(): SupportedLocale {
const savedLanguage = localStorage.getItem('language') as SupportedLocale | null
if (savedLanguage !== null) {
return savedLanguage
try {
const authStore = useAuthStore()
if (authStore.settings.language !== null) {
return authStore.settings.language
}
} catch (e) {
// This may happen on the very first load of Vikunja because setting the language is attempted very early in the lifecycle
console.debug('could not load language from store:', e)
}
const browserLanguage = navigator.language
@ -67,8 +73,3 @@ export function getCurrentLanguage(): SupportedLocale {
return language || DEFAULT_LANGUAGE
}
export async function saveLanguage(lang: SupportedLocale) {
localStorage.setItem('language', lang)
await setLanguage()
}