Skip to content
Snippets Groups Projects
Commit 7150c824 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: store selected locale in localStorage

parent 250b8513
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,10 @@ import Polyglot from 'node-polyglot'
import { App, computed, reactive } from 'vue'
import { has } from '@/utilities'
const DEFAULT_LOCALE = import.meta.env.VUE_APP_DEFAULT_LOCALE ?? 'de'
const STORAGE_KEY = 'aura:locale'
const DEFAULT_LOCALE =
localStorage.getItem(STORAGE_KEY) ?? import.meta.env.VUE_APP_DEFAULT_LOCALE ?? 'de'
const locales = Object.fromEntries(
Object.entries(import.meta.glob('./??.js', { import: 'default', eager: true })).map(
......@@ -44,6 +47,7 @@ function updateLocale(newLocale: string): void {
if (has(locales, newLocale)) {
state.locale = newLocale
state.polyglot = createPolyglot(newLocale)
localStorage.setItem(STORAGE_KEY, newLocale)
} else {
throw new Error(`Unknown locale code for language: ${newLocale}`)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment