Skip to content
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

How to extend Nuxt I18n translations? #2956

Closed
caiotarifa opened this issue Dec 23, 2024 · 3 comments
Closed

How to extend Nuxt I18n translations? #2956

caiotarifa opened this issue Dec 23, 2024 · 3 comments
Labels
question Further information is requested v3 #1289

Comments

@caiotarifa
Copy link

Description

I recently updated to the v3, which now uses Nuxt I18n for its own component translations. Since this update, my existing i18n configuration no longer works as expected. It seems the framework’s new i18n setup conflicts with or overrides my own translations, and I’m unable to figure out how to properly extend its default localization to include my own.

Could you please provide guidance on how to configure or extend the new i18n setup so that my existing translations remain functional?

@caiotarifa caiotarifa added question Further information is requested v3 #1289 labels Dec 23, 2024
Copy link
Member

@caiotarifa
Copy link
Author

Have you checked https://ui3.nuxt.dev/getting-started/i18n/nuxt?

Yes. I had a bit of trouble understanding how to "extend" a language to add new messages or modify an existing message.

@benjamincanac, another thing I had difficulty with is related to this section described in the documentation.

<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'

const { locale } = useI18n()

const lang = computed(() => locales[locale.value].code)
const dir = computed(() => locales[locale.value].dir)

useHead({
  htmlAttrs: {
    lang,
    dir
  }
})
</script>

<template>
  <UApp :locale="locales[locale]">
    <NuxtPage />
  </UApp>
</template>

This doesn't work with languages ​​that contain the country in the code, as the translation file is non-standard, pt_br instead of pt-BR.

Image

To get around this, I'm using the code below, but I don't know if it's recommended.

<script setup>
import * as locales from '@nuxt/ui/locale'

const { locale } = useI18n()

const currentLocale = computed(() =>
  Object.values(locales).find(item => item.code === locale.value)
)
</script>

<template>
  <UApp :locale="currentLocale">
    <NuxtPage />
  </UApp>
</template>

Copy link
Member

Why do you want to extend a language? This i18n system is only there to translate the internals of the Nuxt UI components. If you want to translate your app, you can use Nuxt i18n and define your own locales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested v3 #1289
Projects
None yet
Development

No branches or pull requests

2 participants