#Nuxt i18n not keeping language

4 messages · Page 1 of 1 (latest)

fading whaleBOT
#

Hi @twin whale. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, it seems that you're experiencing an issue with Nuxt 3 and i18n language detection. This behavior is not intended, and there are a few things you can check to resolve the issue:

  1. Configuration Location: Make sure your i18n configuration is in the correct file. As mentioned in this Stack Overflow post (https://stackoverflow.com/questions/77430938), the configuration should be in the nuxt.config.ts file, not in i18n.config.ts.

  2. Configuration Structure: Ensure your configuration in nuxt.config.ts includes the necessary settings. Here's an example:

export default defineNuxtConfig({
  modules: ['@nuxtjs/i18n'],
  i18n: {
    locales: [
      { code: 'en', iso: 'en-US' },
      { code: 'fr', iso: 'fr-FR' }
    ],
    defaultLocale: 'en',
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: 'i18n_redirected',
      redirectOn: 'root'
    }
  }
})
  1. Browser Detection: The detectBrowserLanguage option should be set to ensure the browser language is detected and maintained across page navigation.

  2. Strategy: If you want the language to be included in the URL path, you can set the strategy option. For example:

strategy: 'prefix_except_default'

This will add the language code to the URL for non-default languages.

  1. Persistence: To maintain the selected language across page navigation, make sure you're using the appropriate methods to change the language, such as setLocale() from the useI18n() composable.

If you've checked these points and are still experiencing issues, it might be helpful to review your entire Nuxt and i18n setup, or consider creating a minimal reproduction of the problem to get more specific help.

#

@twin whale Kapa.ai is still learning and improving, please let me know how I did by reacting below.