Jeziki, WIP izbor jezika, store za stanje strani

Jurij Podgoršek 2024-04-01 15:25:09 +02:00
parent 615a2586f2
commit e17ba84505
9 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<script setup="setup">
const store = useNastavitveStore()
const izbraniJezik = computed(() => store.izbraniJezik)
const kodeJezikov = computed(() => Object.keys(store.mozniJeziki))
const kodeDrugihJezikov = computed(() => kodeJezikov.value.filter(
(jezik) => jezik !== store.izbraniJezik
))
const slikaJezika = (jezik) => `/images/jezik_${jezik}.png`
console.log('izbrani jezik!', izbraniJezik.value)
const izbor = ref(false)
</script>
<template>
<div class="izbor">
<div @click="izbor = !izbor">
<img :src="slikaJezika(izbraniJezik)" /> {{ store.mozniJeziki[izbraniJezik] }}
</div>
<div class="drugiJeziki" v-if="izbor">
<div class="jezik" v-for="jezik in kodeDrugihJezikov" @click="() => { store.izberiJezik(jezik); izbor = false }">
<img :src="slikaJezika(jezik)" /> {{ store.mozniJeziki[jezik] }}
</div>
</div>
</div>
</template>
<style>
.izbor {
width: 7rem;
cursor: pointer;
}
img {
position: relative;
top: 5px;
}
</style>

View File

@ -0,0 +1,4 @@
{
"domov": "home",
"jugofuturizem": "yugofuturism"
}

View File

@ -0,0 +1,4 @@
{
"domov": "home",
"jugofuturizem": "yugofuturism"
}

View File

@ -0,0 +1,3 @@
{
"jugofuturizem": "jugofuturizem"
}

View File

@ -0,0 +1,3 @@
{
"jugofuturizem": "jugofuturizem"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 514 B

View File

@ -0,0 +1,19 @@
export const useNastavitveStore = defineStore('nastavitve', {
state: () => ({
izbraniJezik: 'hr',
mozniJeziki: {
si: 'Slovensko',
hr: 'Hrvatski',
en: 'English'
}
}),
actions: {
izberiJezik(jezik) {
if (Object.keys(this.mozniJeziki).indexOf(jezik) >= 0) {
this.izbraniJezik = jezik
console.log(useNuxtApp().$i18n.availableLocales)
//useNuxtApp().$i18n.setLocale(jezik)
}
}
}
})