-
-
Notifications
You must be signed in to change notification settings - Fork 18
How to save the selected language? #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Up! I'm trying to figure it out myself... |
UPDATE - found a solution that works. Hope this will help others! <script setup lang="ts">
import { useI18n } from 'vue-i18n'
const { locale } = useI18n()
const config = useRuntimeConfig()
locale.value = 'en' || config.DEFAULT_LANGUAGE
function setLocale(value) {
locale.value = value
// TODO: save the locale in local storage or cookie...
// localStorage.set('locale', value)
}
onMounted(() =>{
// TODO: get the locale from local storage or cookie and set it...
// locale.value = localStorage.get('locale')
})
</script>
<template>
<q-btn flat dense icon="flag" class="q-mr-md"
><q-menu
><q-list>
<q-item
v-close-popup
clickable
:active="$i18n.locale == 'en'"
@click="setLocale('en')"
>
<q-item-section avatar>
<q-icon name="flag" />
</q-item-section>
<q-item-section>
<q-item-label>English</q-item-label>
</q-item-section>
</q-item>
<q-item
v-close-popup
clickable
:active="$i18n.locale == 'ro'"
@click="setLocale('ro')"
>
<q-item-section avatar>
<q-icon name="flag" />
</q-item-section>
<q-item-section>
<q-item-label>Romanian</q-item-label>
</q-item-section>
</q-item>
</q-list></q-menu
></q-btn
>
</template> |
thank you |
I used to use locale: localStorage.getItem("lang") || "ru", but what is the right way to do it here?
The text was updated successfully, but these errors were encountered: