Contentful logo

Contentful Community

Locales & Static Pages

Hello,

I don’t know if this has already been answered, but I just couldn’t find the answer.
We are generating the static pages (npm run generate) from Contentful. With only one language, we don’t have any issue.

Once you’ve generated the static page, it will create an index.html file. For one locale, this is OK. But when you have two locales defined in Contentful (EN & FR), how the static page going to be ? How to deal with two locales when you only have one static page ?

It’s going to depend on how you’ve configured your page. Contentful will give you whatever data you want when you ask for it.

Some ideas:

You can set it up so you create multiple versions of pages (index_en.html or index_FR.html) and serve which one is appropriate.

Alternatively you could have your pages dynamically change what fields are being displayed using JS on the front end as a user selects different languages. This would result in a bit larger files since you’d be storing multiple language versions of the content in the one big index file.

Hopefully that gives you some ideas to get started.