Nuxt3 i18n, how to use localePath and stuff in script setup #1505
Replies: 1 comment
-
I've also faced this difficulty and I realised that there are several ways to go around this. Since you are starting the link with If you wish to keep the <script setup>
const { t } = useI18n();
const localePath = useLocalePath();
</script>
<template>
<NuxtLink :to="localePath(`/${t('about')}`)">
{{ t('about') }}
</NuxtLink>
</template> If you wish to do away with the <script setup>
const { locale } = useI18n();
const localePath = useLocalePath();
</script>
<template>
<NuxtLink :to="localePath(`about__${locale}`)">
About
</NuxtLink>
</template> Hopefully this is able to give an idea and resolve your problem! |
Beta Was this translation helpful? Give feedback.
-
Hey guys,
I am using Nuxt3 with i18n. I am able to switch language between English and Dutch, and I can use anything inside my but when I want to use stuff in my <script setup></script> that is where I don't know how to do it.
en: '/about-us',
nl: '/over-ons'
And when I would use localePath('/about-us') it would automatically use the correct one of the two above. How to do this in Nuxt 3?
Been Googling for hours but without any success. Hope someone can help me out!
Beta Was this translation helpful? Give feedback.
All reactions