I18n-module: Enabling "fallbackLocale" in "detectBrowserLanguage" intereferes with static page generation by breaking prerendering

Created on 27 Apr 2020  路  2Comments  路  Source: nuxt-community/i18n-module

Version

nuxt-i18n: 6.10.1
nuxt: 2.12.2

Reproduction Link

https://codesandbox.io/s/romantic-neumann-y1bd1?file=/nuxt.config.js

Steps to reproduce

I want to prerender 6 pages for the route of "pages\gen_id\index.vue".
In the page I console.log the payload once it's received in the async data method.

  1. Run "npm generate"
  2. Check the console. You will see it only logged out the payload for pages with the default locale. ("en/gen/1", "en/gen/2"). Meaning only 2 pages of the initial 6 will be pre-rendered.

  3. Now comment out the "fallbackLocale" option in the i18n object in nuxt.config.js

  4. Run "npm generate"
  5. Check the console. Now it will have logged out the payload for every page

What is Expected?

"fallbackLocale" option should not interefere with static page generation.

What is actually happening?

When "fallbackLocale" option is enabled, pages which are not of default locale do not get pre-rendered.

bug 馃悰

Most helpful comment

I can see this happening as the module will redirect to default locale if there is no cookie set yet and I'm assuming that during generation cookies are not sent or saved. This will probably also happen with alwaysRedirect: true.

It probably makes sense to special-case generation of pages. It would just need to be reliably detectable from a plugin. I will have a look at some point.

EDIT: Actually it's enough that it's detectable from a module and that should be possible.

All 2 comments

I can see this happening as the module will redirect to default locale if there is no cookie set yet and I'm assuming that during generation cookies are not sent or saved. This will probably also happen with alwaysRedirect: true.

It probably makes sense to special-case generation of pages. It would just need to be reliably detectable from a plugin. I will have a look at some point.

EDIT: Actually it's enough that it's detectable from a module and that should be possible.

Resolved by #718 (spinned out from #715)

Was this page helpful?
0 / 5 - 0 ratings