#implementing multilingual support

1 messages · Page 1 of 1 (latest)

pastel matrix
#

Hi everyone! I'm having some trouble implementing multilingual support on my Astro site and would really appreciate some help.

I've already set up translated pages and a language switch button. The general pages switch correctly between /pt/ and /en/ paths. However, I'm struggling to make this work properly for blog or news posts.

Each post is written in .md files under language-specific folders like:

src/content/noticias/pt/noticia-1.en.md
src/content/noticias/noticia-1.pt.md

When I'm on a specific post (e.g. noticia-1.pt) and click the language switch button, I want it to check if the same slug exists in the other language (noticia-1.en).

If it exists, go to that post.

If it doesn't, fall back to the listing page in that language (/en/noticias).

Right now, I can't figure out how to implement this logic without relying on fetch() or client-side 404 handling. I want everything to be handled at build time using the data available from the .md files.

For context:
I'm currently refactoring the entire project to use Astro exclusively (removing React), and soon I plan to integrate the content layer with Strapi.

/src/pages/[lang] is folder that is working

Repo (refactor branch):
🔗 https://github.com/labriunesp/nefits/tree/refatorar

Any ideas, patterns, or examples of how to cleanly implement this behavior in Astro? Thanks a lot in advance!

GitHub

Site do grupo de pesquisa NEFITS. Contribute to labriunesp/nefits development by creating an account on GitHub.

unborn patio
#

If you already do it this way, then you could just add your blog posts to the routes.