i18n fallback: what my site shows when a translation string is missing
My downloader site, ramrom.io, has a language selector with nine languages. The tool buttons, the placeholder in the link box, the error messages — all of it comes from a tiny JavaScript dictionary, no framework, no buil
My downloader site, ramrom.io, has a language selector with nine languages. The tool buttons, the placeholder in the link box, the error messages — all of it comes from a tiny JavaScript dictionary, no framework, no build step.
I have learned that the fallback matters more than the translation. A visitor who picks Urdu and gets a blank button thinks the site is broken. A visitor who picks Urdu and gets an English word thinks the site is half-finished, but they can still use it. One of those two is a failed visit. The other is a minor blemish.
Here is how the dictionary is laid out. There is one object per language, keyed by the same string IDs everywhere. English is the reference copy: every key exists in English first, because the page ships in English and every new string is written there before it is translated. The lookup function is small on purpose. It takes a key and a language, checks that language's object, and if the key is not there, it returns the English string. Only if English is missing too — which should never happen, since the English copy is written by hand — does it fall back to the key itself.
function t(key) {
const lang = dict[currentLang] || {};
if (lang[key]) return lang[key];
if (dict.en[key]) return dict.en[key];
return key;
}
The important detail is what the function does not do. It never returns an empty string. It never returns undefined and lets the page render a blank. And it never crashes. A missing translation is a content gap, not an exception, so it should behave like one.
I also log the miss. Every time the English fallback fires, a small line goes into the browser console with the key and the language. I do not send it to the server — the site stores nothing about visitors — but when I test a language myself I can open the console and see exactly which strings still need translating. That list is my translation to-do list, and it comes from real lookups, not guesswork.
There are two traps I have had to watch for. The first is a key that exists in a language but with an empty string as its value. My first version of the lookup used lang[key] || dict.en[key], which treats an empty string as missing and falls back correctly — but a later rewrite that checked key in lang would have returned the empty string and shown a blank button. An empty translation is worse than a missing one, because the lookup thinks the work is done. Now every language file is checked before upload: any empty value gets flagged, and the key is left out entirely so the fallback can do its job.
The second trap is keys that only exist on one page. The dictionary is shared across the whole site, but not every page uses every key. A string that only appears on the Instagram page can sit untranslated for weeks because I only test the homepage in each language. So when I add a new page, I test that page in every language too — or at least open the console and let the fallback log tell me what is missing.
One more decision: I never show the key itself to a visitor if I can avoid it. Keys like download_btn_label are fine in code, but a visitor who sees one on a button knows instantly that something is broken. The key is the last-resort return in the function, there so the page never blanks out, but if it ever shows up in production I treat it as a bug, not a fallback.
The wider lesson is simple. Translation is never finished on a site that keeps growing, so the fallback is not a temporary hack — it is a permanent part of the design. Build it first, make it boring, and let it quietly cover the gaps while you translate the rest.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.