i18n icon indicating copy to clipboard operation
i18n copied to clipboard

DetectBrowserLanguage rollback to default locale when using `prefix_except_default`

Open timothejoubert opened this issue 1 year ago • 0 comments

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

timothejoubert avatar Jul 23 '24 13:07 timothejoubert