3 page links in the nav should be displayed in 3 languages by user choice. In the initial page load it works fine. Then click one language change link then again it works fine. But when I click a language change link another time only the last link’s language changes when all of them should change language. What is causing this problem and how to fix it?
app.vue:
<template>
<nav class="navbar">
<NuxtLink class="pagelink" :key="page.slug" v-for="page in strings.pages" :href="'/' + page.slug">{{ page.name[lang] }}</NuxtLink>
<Languages />
</nav>
</template>
<script>
import Languages from "./components/languages.vue"
import languages from "../services/languages"
export default {
name: "Navbar",
data() {
return {
open: false,
strings: {
pages: [
{
slug: 'home',
name: { az: "Əsas", ru: "Главная", en: "Home" }
},
{
slug: 'about',
name: { az: "Haqqımızda", ru: "О нас", en: "About" }
},
{
slug: 'contact',
name: { az: "Əlaqə", ru: "Связаться", en: "Contact Us" }
}
]
}
}
},
computed: {
lang() {
return languages(this)
}
}
}
</script>
<style>
* {
margin: 10px;
}
</style>
languages.vue:
<template>
<div class="languages">
<NuxtLink :to="route.path + '?hl=az'">AZ</NuxtLink>
<NuxtLink :to="route.path + '?hl=ru'">RU</NuxtLink>
<NuxtLink :to="route.path + '?hl=en'">EN</NuxtLink>
</div>
</template>
<script>
export default {
name: "Languages",
setup() {
const route = useRoute()
return {
route
}
}
}
</script>
<style scoped>
div,
div a {
height: 40px;
display: inline-block;
}
img {
height: 60%;
display: inline-flex;
margin: 8px;
}
</style>
languages.js:
function languages(page) {
let langCookie = useCookie("language")
let language = langCookie.value
if (page.$route.query.hl) {
language = page.$route.query.hl
langCookie.value = language
}
return language || 'az';
}
export default languages