
Nine Languages, Zero i18n Libraries: The Pattern I Keep Rebuilding From Scratch
No i18n library, seven side projects, 2-9 languages each. The typed dictionary pattern I keep reusing, and the reload bug and RTL bug that shaped it.
I've shipped multi-language support in seven side projects now — a quantum fortune-telling app in 9 languages, an AI debate arena in 8, a Minecraft bot dashboard in 8, a couple of Japanese/English tools. Not once have I reached for
next-intl or react-i18next . Every single time it's the same 40-line pattern: a TypeScript object shaped like Record<LangCode, Dict> , a hook to read it, done. This post is what that pattern looks like, why it kept winning over "just install the real library," and the two mistakes I made before it stopped feeling half-baked.The shape that keeps showing up
Here's the dictionary from Quantum Omikuji , a fortune-telling app where the result comes from an actual quantum measurement instead of
Math.random() :export const LANGS = [ { code: "ja", label: "日本語", dir: "ltr" }, { code: "en", label: "English", dir: "ltr" }, { code: "ar", label: "العربية", dir: "rtl" }, // ...] as const;
export type LangCode = (typeof LANGS)[number]["code"];
export type Messages = { tagline: string; observe: string; histTitle: string; // {n} // ...};
export const MESSAGES: Record<LangCode, Messages> = { ja: { tagline: "運勢は、観測するまで決まっていない。", observe: "観測する", /* ... */ }, en: { tagline: "Your fortune is not decided until you observe it.", observe: "Observe", /* ... */ }, // ...};That's the whole thing. One file, one type, one object literal per language. Placeholders like
{n} get swapped with a tiny fmt() helper instead of a full ICU MessageFormat parser. No routing changes, no build-time extraction step, no translation-key linter. And because the Messages type is shared across every language entry, TypeScript itself catches a missing key the moment you add a new language and forget one string — which, with 9 languages and a couple dozen strings, happens more than I'd like to admit.The translation itself isn't the bottleneck people expect it to be. I write the English and Japanese strings by hand, then hand the
Messages type and those two entries to Claude and ask it to fill in the rest, matching tone and keeping placeholders intact. For a UI with 20-30 short strings this takes a couple of minutes and the output is good enough to ship without a professional review pass — this is side-project software, not a shipping label that needs to survive a lawsuit.Mistake #1: state that forgets you
The first two apps I built this way — the AI debate arena and an AI-text-detector tool — stored the language in plain
useState . It worked fine in every manual test I ran, because I never actually reloaded the page mid-session. A friend tried the debate app, switched to English, then hit refresh to start a new match, and landed right back in Japanese. Small thing, but it's exactly the kind of bug you don't see until someone who isn't you uses the product the way real users actually do — open a tab, close it, come back tomorrow.Mistake #2 → the fix: useSyncExternalStore, not useState
The obvious fix is
localStorage . The less obvious problem is that reading localStorage directly inside a component during render breaks server-side rendering — the server has no window , so it renders one thing, the client hydrates to another, and React complains about a hydration mismatch. The pattern that fixed it for good, from AI Hype Checker :function getLocaleSnapshot(): Locale { if (memoryLocale) return memoryLocale; try { const stored = window.localStorage.getItem(STORAGE_KEY); if (stored && stored in DICTIONARIES) return stored as Locale; } catch { /* ignore */ } const nav = (typeof navigator !== "undefined" ? navigator.language : "") .slice(0, 2).toLowerCase(); if (nav && nav in DICTIONARIES) return nav as Locale; return DEFAULT_LOCALE;}
const locale = useSyncExternalStore(subscribe, getLocaleSnapshot, () => DEFAULT_LOCALE);useSyncExternalStore 's third argument is the server snapshot, always the default locale, so the server and the first client render agree. Right after hydration, React re-renders with whatever getLocaleSnapshot() actually finds in localStorage — the saved choice, or a navigator.language guess if there's no saved choice yet. No flash of the wrong language that I've noticed, no hydration warning in the console. This is the version I now copy into every new project.The one RTL bug that made me actually think
Two of the apps support Arabic, and the first time I added it I just... translated the strings and shipped. It looked fine in my screenshot because I'd only checked the hero section, where the text happened to still read left-to-right well enough not to look broken. It was the button row underneath — icon, then label — that gave it away: in Arabic the icon needs to sit on the right of the label, not the left, or the layout reads as visually reversed even though the words themselves are correct. The fix is genuinely two lines:
export const RTL_LANGS: Lang[] = ["ar"];// in the component:const isRtl = RTL_LANGS.includes(lang);...and then threading
dir={isRtl ? "rtl" : "ltr"} onto the root container so flexbox rows flip direction automatically. Cheap to add, easy to forget entirely if you don't have an Arabic speaker to actually look at it — I didn't, and I only caught the button issue by mentally reading the layout right-to-left myself and noticing it felt wrong.Why not just use the library
next-intl and react-i18next earn their keep on things this pattern doesn't even attempt: plural rules that vary by language (not every language treats "1 vs many" the same way English does), server-side locale routing, message extraction tooling, translator handoff workflows. None of that shows up in a solo side project with no separate translation team and no SEO requirement for /en/ versus /ja/ URLs. What I actually need is "swap the strings, remember the choice, don't break on Arabic" — and a single typed object gets there in less code than the config for most i18n libraries.The trade-off is real, though: pluralization here is whatever ad-hoc function I write per string (
histTitle: (n) => ... ), not a spec-compliant CLDR plural rule, and if one of these projects ever needed a dozen contributors translating in parallel, I'd reach for the real tooling instead of fighting my own object literal. For a project with one developer and Claude filling in the blanks, that hasn't happened yet.Takeaways
- A
Record<LangCode, Dict>object plus a hook beats a library at this scale. TypeScript's own exhaustiveness checking catches missing translations for free, and there's no config to learn.
-
useSyncExternalStoreoveruseStatethe momentlocalStorageis involved — it's the difference between a language choice that survives a refresh and one that quietly resets, and it sidesteps the SSR hydration mismatch that readinglocalStoragedirectly during render would cause.
- RTL is not just "translate the string." Layout direction has to flip too, and the bug hides in whichever component you didn't happen to screenshot.
- Let the model fill in the dictionary. Write the strings in the two languages you actually speak, hand the type definition to Claude, and let it match tone across the rest — it turns "add a ninth language" from a chore into a five-minute task.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article