← Back to blog

Adding Galician to our own site: what we learned doing i18n without libraries

Daniel García·

A few weeks ago we decided to add Galician to our own website, alongside Spanish and English. It wasn’t a client request or part of some expansion plan: it was Marta, who runs the commercial side, mentioning one day that a good chunk of the people who reach us through LinkedIn are from Galicia, and that a few of them found it odd the site only showed up in Spanish and English, never in their own language. It wasn’t a formal complaint, more a hallway comment. But it stuck with me.

The first call we made was not to pull in an i18n package. Astro has had built-in language-prefixed routing for a couple of versions now, but we were already using the Content Layer API with loader: glob for the blog and the FAQ, so the simplest fix was to add a per-language subfolder inside each collection (blog/es/, blog/en/, blog/gl/, same thing under faq/). Same filename across all three folders, so translations of the same piece pair up automatically. No translation table in a database, no third-party plugin.

Translating wasn’t what took the most time. I do that myself, without running the text through any machine translation tool first — I’ve spoken Galician since I was a kid, and you can tell right away when a translation came out of a machine, and I don’t want a Galician reader wincing halfway through a paragraph. What did take work was splitting the language prefix from the actual slug when generating routes: getStaticPaths works off entry.id, and on the blog that id has language, date and slug all stuck together. We ended up writing a separate function just to pull that string apart into its three pieces.

Then came the dumb mistake that took a while to spot. We published a post about backups without the es/ prefix in front of the filename. Astro loaded it without complaining, since the collection schema doesn’t require that folder, so the build passed clean. But the post didn’t show up on /blog, or /en/blog, or /gl/blog. No error, no warning in the console — just a ghost post that existed in the repo and nowhere in the browser. I only caught it because I searched the title in the site’s own search bar and got nothing back.

Since then, checking that language folder is one of the first things I do before committing new content. What I still haven’t figured out is what to do with the older pieces: I’m translating them into Galician as I find the time, not all at once, so for a while the Galician version of the language switcher is going to show noticeably fewer posts than Spanish or English. I don’t know if that’s more confusing than helpful, or if it’s actually better this way, bit by bit, than rushing a translation of forty pieces just to look complete.

astroi18narchitecture