The best practice for handling static paths and internationalization in Astro is to generate the correct localized paths for each language in your getStaticPaths() function, matching your folder and URL structure.
Given your file structure:
pages/
|-> products/
| |-> product/
| | |-> index.astro
| [page].astro
|-> pl/
| |-> produkty/
| | |-> produkt/
| | | |-> index.astro
| [page].astro
You should generate static paths that correspond to the localized routes. For example:
- For English:
/products/product/[page]
- For Polish:
/pl/produkty/produkt/[page]
This means you will need to return different values from getStaticPaths() for each language, so that the generated URLs match your folder structure and desired routes.
How to implement:
- In each
[page].astro file (one in products/product/ and one in pl/produkty/produkt/), implement a getStaticPaths() that returns the correct slugs for that language.
- For English, return slugs like
{ params: { page: 'some-product' } } for /products/product/[page].
- For Polish, return slugs like
{ params: { page: 'jakis-produkt' } } for /pl/produkty/produkt/[page].
You do not need to combine both languages in a single getStaticPaths(); each localized route should have its own function, returning only the slugs relevant to that language and path. This matches Astro's file-based routing and i18n best practices, where each language's content lives in its own folder and is generated independently see example.
If you use content collections, you can filter or map your content by language and generate the appropriate paths for each [page].astro file see content collections example.