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

DetectBrowserLanguage rollback to default locale when using prefix_except_default #3039

Open
timothejoubert opened this issue Jul 23, 2024 · 0 comments

Comments

@timothejoubert
Copy link

Environment

  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.12.4
  • CLI Version: 3.12.0
  • Nitro Version: -
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, runtimeConfig, i18n, compatibilityDate
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-i18n-timothe?file=app.vue,pages/%5B...slug%5D.vue,nuxt.config.ts

Describe the bug

When using prefix_except_default strategy, and try to initialize locale with setLocale function but I18n fallback to default locale afterward. It's only work when I set detectBrowserLanguage to {} instead of false.

Additional context

I let the CMS handle the routing for the wildcard.

Logs

isSSG false
useCookie on setup false
defaultLocale on setup fr
getLocaleCookie { useCookie: false, cookieKey: false, localeCodes: [ 'fr', 'en' ] }
detectLocale: initialLocale - fr
detectLocale: (ssg, callType, firstAccess) -  normal setup true
detectLocale: detectBrowserLanguage (browserLocale, stat, reason, from) -  false unknown unknown
detectLocale: finaleLocale first (finaleLocale, strategy) -  prefix_except_default
detectLocale: finaleLocale second (finaleLocale, detectBrowserLanguage) -  false
detectLocale: finalLocale last (finalLocale, defaultLocale) -  fr
detectLocale: finalLocale - fr
first detect initial locale fr
../assets/fr.json is loading ...
loadMessage: (locale) - fr
loadMessage: load { welcome:
   { type: 0,
     start: 0,
     end: 9,
     loc: { start: [Object], end: [Object], source: 'Bienvenue' },
     body:
      { type: 2, start: 0, end: 9, loc: [Object], items: [Array], static: 'Bienvenue' } } }
final initial locale: fr
locale-changing middleware { fullPath: '/',
  hash: '',
  query: {},
  name: 'slug',
  path: '/',
  params: { slug: '' },
  matched:
   [ { path: '/:slug(.*)*',
       redirect: undefined,
       name: 'slug',
       meta: {},
       aliasOf: undefined,
       beforeEnter: undefined,
       props: [Object],
       children: [],
       instances: {},
       leaveGuards: Set(0) {},
       updateGuards: Set(0) {},
       enterCallbacks: {},
       components: [Object] } ],
  meta: {},
  redirectedFrom: undefined,
  href: '/' } { fullPath: '/',
  path: '/',
  query: {},
  hash: '',
  name: undefined,
  params: { slug: '' },
  matched:
   [ { path: '/:slug(.*)*',
       redirect: undefined,
       name: 'slug',
       meta: {},
       aliasOf: undefined,
       beforeEnter: undefined,
       props: [Object],
       children: [],
       instances: {},
       leaveGuards: Set(0) {},
       updateGuards: Set(0) {},
       enterCallbacks: {},
       components: [Object] } ],
  meta: {},
  redirectedFrom: undefined,
  href: '/' }
getLocaleCookie { useCookie: false, cookieKey: false, localeCodes: [ 'fr', 'en' ] }
detectLocale: initialLocale - fr
detectLocale: (ssg, callType, firstAccess) -  normal routing true
detectLocale: detectBrowserLanguage (browserLocale, stat, reason, from) -  false unknown unknown
detectLocale: finaleLocale first (finaleLocale, strategy) -  prefix_except_default
detectLocale: finaleLocale second (finaleLocale, detectBrowserLanguage) -  false
detectLocale: finalLocale last (finalLocale, defaultLocale) -  fr
detectLocale: finalLocale - fr
detect locale fr
localeSetup false
setLocale: new ->  fr  old ->  fr  initial ->  false
detectRedirect: targetLocale ->  fr
detectRedirect: route ->  { to:
   { fullPath: '/',
     hash: '',
     query: {},
     name: 'slug',
     path: '/',
     params: { slug: '' },
     matched: [ [Object] ],
     meta: {},
     redirectedFrom: undefined,
     href: '/' },
  from:
   { fullPath: '/',
     path: '/',
     query: {},
     hash: '',
     name: undefined,
     params: { slug: '' },
     matched: [ [Object] ],
     meta: {},
     redirectedFrom: undefined,
     href: '/' } }
detectRedirect: calledWithRouting ->  true 
detectRedirect: calculate routePath ->   /
redirectPath on locale-changing middleware 
navigate options  302  false false false
navigate isSSG false
setLocale: new ->  en  old ->  fr  initial ->  true
../assets/en.json is loading ...
loadMessage: (locale) - en
loadMessage: load { welcome:
   { type: 0,
     start: 0,
     end: 7,
     loc: { start: [Object], end: [Object], source: 'Welcome' },
     body: { type: 2, start: 0, end: 7, loc: [Object], items: [Array], static: 'Welcome' } } }
detectRedirect: targetLocale ->  en
detectRedirect: route ->  { to: {} }
detectRedirect: calledWithRouting ->  false 
detectRedirect: calculate routePath ->   /
redirectPath on setLocale 
navigate options  302  false false true
navigate isSSG false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant