How to make internalization languages in NuxtJS 3?

Is it possible to apply the internalization languages in NuxtJS 3?
2 Replies
kapa.ai
kapa.ai2w ago
Hi @Adnan Erlansyah. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, it is possible to implement internationalization (i18n) in Nuxt 3. Nuxt 3 has official support for internationalization through the @nuxtjs/i18n module. Here's a brief overview of how to set it up: 1. Install the @nuxtjs/i18n module in your Nuxt 3 project. 2. Configure the module in your nuxt.config.ts file:
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
vueI18n: './i18n.config.ts'
}
})
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
vueI18n: './i18n.config.ts'
}
})
3. Create an i18n.config.ts file in your project root to define your locales and translations:
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
en: {
welcome: "Welcome"
},
fr: {
welcome: "Bienvenue"
}
}
}))
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
en: {
welcome: "Welcome"
},
fr: {
welcome: "Bienvenue"
}
}
}))
4. Use the translations in your Vue components:
<template>
<p>{{ $t('welcome') }}</p>
</template>

<script setup>
const { locale, setLocale } = useI18n()
</script>
<template>
<p>{{ $t('welcome') }}</p>
</template>

<script setup>
const { locale, setLocale } = useI18n()
</script>
This setup allows you to easily manage multiple languages in your Nuxt 3 application. For more detailed information and advanced usage, you can refer to the @nuxtjs/i18n documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@1079709612078534676> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?