Skip to content

Commit 56cb4fa

Browse files
committed
Store locale settings
1 parent c4858b6 commit 56cb4fa

5 files changed

Lines changed: 93 additions & 4 deletions

File tree

frontend/package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dependencies": {
1515
"@mdi/font": "^7.4.47",
1616
"pinia": "^3.0.4",
17+
"pinia-plugin-persistedstate": "^4.7.1",
1718
"sql.js": "^1.13.0",
1819
"vue": "^3.5.25",
1920
"vue-router": "^4.6.4",

frontend/src/components/SettingsView.vue

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
<script setup>
2-
import {onMounted, onUnmounted} from "vue";
2+
import {onMounted, onUnmounted, ref} from "vue";
3+
import { useLocaleStore } from '@/stores/locale'
4+
5+
const localeStore = useLocaleStore()
6+
7+
const langs = ref([
8+
{lang: 'bg', name: 'Български'},
9+
{lang: 'ca', name: 'Català'},
10+
{lang: 'de', name: 'Deutsch'},
11+
{lang: 'en', name: 'English'},
12+
{lang: 'el', name: 'Ελληνικά'},
13+
{lang: 'es', name: 'Español'},
14+
{lang: 'fa', name: 'فارسی'},
15+
{lang: 'fr', name: 'Français'},
16+
{lang: 'it', name: 'Italiano'},
17+
{lang: 'nl', name: 'Nederlands'},
18+
{lang: 'pl', name: 'Polski'},
19+
{lang: 'pt', name: 'Português'},
20+
{lang: 'ru', name: 'Русский'},
21+
{lang: 'tr', name: 'Türkçe'},
22+
{lang: 'uk', name: 'Український'},
23+
]);
324
425
const props = defineProps({
526
title: String,
@@ -14,15 +35,19 @@ onMounted(async () => {
1435
onUnmounted(async () => {
1536
emit('update:title', oldTitle);
1637
})
38+
39+
const changeLanguage = (lang) => {
40+
localeStore.setLocale(lang)
41+
}
1742
</script>
1843

1944
<template>
2045
<v-container>
2146
<v-list>
2247
<v-list-item>
2348
<v-btn-toggle
24-
rounded="xl"
25-
border
49+
rounded="xl"
50+
border
2651
>
2752
<v-btn icon="mdi-weather-night"></v-btn>
2853
<v-btn icon="mdi-brightness-auto"></v-btn>
@@ -31,7 +56,11 @@ onUnmounted(async () => {
3156
</v-list-item>
3257
<v-list-item>
3358
<v-select
34-
:items="['English',]"
59+
v-model="localeStore.currentLocale"
60+
:items="langs"
61+
item-title="name"
62+
item-value="lang"
63+
@update:modelValue="changeLanguage"
3564
></v-select>
3665
</v-list-item>
3766
</v-list>

frontend/src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import { createVuetify } from 'vuetify'
99
import { createPinia } from 'pinia'
1010
import * as components from 'vuetify/components'
1111
import * as directives from 'vuetify/directives'
12+
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
1213

1314
// Components
1415
import App from './App.vue'
1516
import router from './router'
1617

1718
const pinia = createPinia()
19+
pinia.use(piniaPluginPersistedstate)
1820

1921
const vuetify = createVuetify({
2022
components,

frontend/src/stores/locale.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineStore } from 'pinia'
2+
import { ref } from 'vue'
3+
4+
export const useLocaleStore = defineStore('locale', () => {
5+
const currentLocale = ref('en')
6+
7+
const setLocale = (locale) => {
8+
currentLocale.value = locale
9+
10+
localStorage.setItem('app-locale', locale)
11+
12+
document.documentElement.lang = locale
13+
14+
window.dispatchEvent(new CustomEvent('locale-changed', {
15+
detail: { locale }
16+
}))
17+
}
18+
19+
return {
20+
currentLocale,
21+
setLocale,
22+
}
23+
}, {
24+
persist: true,
25+
})

0 commit comments

Comments
 (0)