Generate routes for all languages

Hi!

I was wondering how to generate routes for my website which has multiple languages.

I'm using the nuxt full static mode (hosting on Netlify) and currently the pages are only generated for my default language.

Example:
√ Generated route "/"
√ Generated route "/preview"
√ Generated route "/fr-ch/contact"
√ Generated route "/fr-ch/services"
√ Generated route "/fr-ch/energy-advice"
√ Generated route "/fr-ch/solutions"
√ Generated route "/fr-ch"

But I have routes like /en-us/services that are never generated. This issue resolves in a 404 on static hosting when you try to directly access the url.

Working link: https://kach.netlify.app/fr-ch/
404 link: kach-conseils | undefined

Thanks a lot if someone has an idea!

1 Like

Hey Valerin, welcome to the Prismic forum!

How are you handling the internationalisation of the site?
Luckily we have an example project if you'd like to see how we do it:

The way he handle it is, first with a folder structure that constructs the URLs. So something like:

For a Homepage and for the dynamic 'posts'

  • /pages/index.vue and /pages/_uid.vue

For the translation and the dynamic 'posts'

  • /pages/_lang/index.vue and /pages/_lang/_uid.vue

Then in the asyncData function there's a variable where we fetch the API response and we use the slug coming from the URL to create each individual route.

How are you doing it?

4 Likes

Hi! Thanks for the answer!

Here is my code: https://github.com/vkaelin/KACH/tree/master/kach-conseils

I also tried the project you linked and it worked great.

I tried to edit my code to looks more like the demo one but still, only the main languages routes are beeing generated.

Thank you again !

Oh, I think it's because I can't use a select like I did to switch from one language to another. It needs to be links so that the generate command knows all the possible pages.

Is it the only way to make it works ?

You could use a select, you would need to get all the alternate languages from a given document and display the variants.

Thanks for the info! I think I will stay with the links version for now.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.