The default language is set in the user's local storage.
import { createApp } from 'vue'
import App from './App.vue'
import createMultilang from "vue3multilang"
const app = createApp(App)
const messages = {
"en-UK":{
welcome:"Welcome, {user}!",
},
"ro-RO":{
welcome:"Bine ati venit, {user}!",
}
}
app.use(createMultilang(),{
locale: "en-UK",
messages,
})
app.mount('#app')
<template>
<div>
<p>{{$t("welcome",{user:"Ricea"})}}</p>
<button @click="changelocale">Change to ro - {{count}}</button>
</div>
</template>
<script>
export default {
data() {
return {
count: 0
}
},
methods:{
changelocale(){
this.count++;
this.$lang.changeLocale("ro-RO");
}
},
}
</script>
<template>
<div>
<p>Welcome, Ricea!</p>
<button @click="changelocale">Change to ro - 0</button>
</div>
</template>
<template>
<div>
<p>Bine ati venit, Ricea!</p>
<button @click="changelocale">Change to ro - 0</button>
</div>
</template>