https://github.com/tex0l/nuxt-i18n-repro-case
Start a static server on a project built using nuxt generate in 'universal' mode. The test case provided does exactly that with an nginx server started with the result of the nuxt generate with docker.
The detectBrowserLanguage feature should be used, just as in 'spa' mode.
The detectBrowserLanguage feature isn't used, considering it should be done server-side, but since there's no server, it doesn't word at all.
The problem lies in the fact that it is done in a middleware: https://github.com/nuxt-community/nuxt-i18n/blob/master/src/templates/middleware.js#L101
When using nuxt generate, the middlewares are executed at build-time, not at run-time.
I worked around the issue by putting this in my layout's mounted method:
if (process.browser) {
if (this.$cookie.get('i18n_redirected') !== '1') {
const lang = navigator.language.toLocaleLowerCase().substring(0, 2)
this.$cookie.set('i18n_redirected', '1')
this.$router.push(this.switchLocalePath(lang))
}
}
}
Same problem here
Above solution works, but this should be mentioned in the documentation.
While the above solution might work in specific cases, the middleware is doing a lot more in the meantime. Imo this issue should be fixed in nuxt-i18n, instead of just mentioning it in the documentation.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I agree on this, it's a pity not to have the detection on generated websites (also trying desperately to make the bot reopen it 馃槵 )
Also agree. The above solution works but shows the default/fallback language translations before - almost immediately - switching to the detected language which, of course, isn't a wanted behavior.
Most helpful comment
While the above solution might work in specific cases, the middleware is doing a lot more in the meantime. Imo this issue should be fixed in nuxt-i18n, instead of just mentioning it in the documentation.