More than a language button
You switch languages halfway through an article. You want to continue at the same section, not land on the homepage. That small expectation shapes how a bilingual site has to store its content.
CodeMeetsAI keeps both editions of an article in one content record, with separate titles, summaries and sections. Node.js generates the HTML pages in advance, so reading a page never calls a translation service.
Which part of the address changes?
Each article has one stable identifier. Replacing en with tr in /en/articles/a-publication-in-two-languages/ opens the Turkish edition; the identifier stays the same in both languages.
The code below carries the current query parameters and section anchor over to the other language. Section anchors are numbered by position rather than generated from translated headings, so the two editions must keep their sections in the same order.
const alternateLink = document.querySelector('[data-language-switch]');
const target = new URL(alternateLink.href);
target.search = location.search;
target.hash = location.hash;
location.href = target.href;What happens when a translation is missing?
The build checks that every required field exists in both languages and that both editions have the same number of sections. It stops instead of quietly filling a missing Turkish text with English.
Drafts are visible in a separate preview build, clearly labelled and kept out of the public article list and feeds.
npm run check
npm run build:preview # includes visibly labeled drafts
npm run dev
# After review and publication metadata:
npm run build # published content onlyTelling search engines about both editions
Each page lists its counterpart with hreflang links for en and tr, plus an x-default. Google’s guidance is strict on one point: every language version must list itself and all other versions, and if two pages do not point to each other the annotations are ignored. Generating both editions from the same record makes those reciprocal links automatic.
Where this approach stops
Static pages load fast and stay readable without JavaScript; the trade-off is that every content change needs a rebuild. There is no shared browser editor or live translation here.
To see the behaviour, scroll to the middle of an article and switch language: you should stay in the matching section. Then open the same page with JavaScript disabled; the content is still there.