nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.75k stars 483 forks source link

Default Locale Not Functioning as Expected: Browser Default Locale Overrides Configured Default Locale #2760

Closed shoaibkhandev closed 9 months ago

shoaibkhandev commented 9 months ago

Environment

Reproduction

i18n: {
        baseUrl: process.env.WEBSITE_URL,
        locales: [
            {
                name: 'Arabic',
                code: 'ar',
                iso: 'ar',
                file: 'ar.json'
            },
            {
                name: 'English',
                code: 'en',
                iso: 'en',
                file: 'en.json'
            }
        ],
        defaultLocale: 'ar',
        strategy: 'prefix',
        lazy: true,
        langDir: 'locales',
        detectBrowserLanguage: {
            useCookie: true,
            cookieKey: 'i18n_redirected',
            alwaysRedirect: true,
            redirectOn: 'root'
        }
    },

Describe the bug

The current implementation of Nuxt.js i18n module does not properly enforce the configured default locale when the application is launched. Instead, it prioritizes the browser's default locale, disregarding the configured default locale. This behavior poses a challenge for users who intend to enforce a specific default language, such as Arabic, regardless of the user's browser settings.

Additional context

No response

Logs

No response

github-actions[bot] commented 9 months ago

Would you be able to provide a reproduction? 🙏

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: 👉 [Reproduction starter (v8 and higher)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/v8) 👉 [Reproduction starter (edge)](https://stackblitz.com/fork/github/BobbieGoede/nuxt-i18n-starter/tree/edge) A public GitHub repository is also perfect. 👌 Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve)
BobbieGoede commented 9 months ago

Closing this due to inactivity.

I actually think what you're experiencing is intended behaviour, detectBrowserLanguage detects and uses the browser language by various means, if you want to ignore the browser language you should set it to false instead. Refer to the docs for more details.

sanjarbarakayev commented 6 months ago

Closing this due to inactivity.

I actually think what you're experiencing is intended behaviour, detectBrowserLanguage detects and uses the browser language by various means, if you want to ignore the browser language you should set it to false instead. Refer to the docs for more details.

I set it to false, but afterward, changing the cookie value stopped working.

shoaibkhandev commented 6 months ago

@sanjarbarakayev Same thing happend with me as well if we set to false the cookie will not work. @BobbieGoede we need a default language that will take precedence over the browser default language

BobbieGoede commented 6 months ago

Please provide a minimal reproduction project and a description of the current behaviour and the expected behaviour, I can't tell if this issue is a bug, misconfiguration or miscommunication.