refactor: t() / bilingual() positional → object form - #32
Merged
Conversation
Replace the positional-argument signatures with a single object keyed by
language code. Same return shapes — t() still returns {primary, secondary},
bilingual() still returns "{target} / {primary}".
Before:
t('Continuer', 'Continue', 'Continuar', '继续', '繼續').primary
After:
t({ fr: 'Continuer', en: 'Continue', es: 'Continuar', 'zh-Hans': '继续', 'zh-Hant': '繼續' }).primary
Why object form:
- Call sites are self-documenting: the key states which language it is.
- Order mistakes (es vs zh-Hans) are now impossible.
- Adding a sixth language no longer ripples through every call site.
Scope:
- LanguageContext.tsx — new exported Translations type, single-arg signatures
- LanguageContext.test.tsx — 3 call sites updated; all language tests still pass
- 350 call sites across 35 files rewritten via AST codemod
- Codemod kept at scripts/codemod-t-object-form.mjs for future similar refactors
- CLAUDE.md "Bilingual System" examples updated to object form
Re-swept on top of current main (post PR #28 font picker, #29 Mandarin,
#30 theme metadata, #31 self-compassion). Single break, single PR — per
the explicit decision in the language pair follow-up plan.
Verification:
- npx tsc --noEmit → clean
- eslint → 11 errors + 27 warnings (zero new vs main baseline)
- vitest → 155/156 pass; the 1 failure (startFreeWrite) is pre-existing on main
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 23, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Convert the
t()andbilingual()helpers inLanguageContext.tsxfrom positional(fr, en, es, zhHans?, zhHant?)arguments to a singleTranslationsobject argument. All 350 call sites swept programmatically via an AST-based codemod (TypeScript compiler API).Return shapes do NOT change:
t()still returns{ primary, secondary },bilingual()still returns"target / primary". No user-visible change. This is pure dev-ergonomics work — pulled out of the original Language Pair PR (#25) for a clean diff per the discussion inmemory/project_language_pair.md.Why now
Translationsis an object — just add a new optional key. With the positional form, every call site would have had to grow a 6th arg.t(badge.fr, badge.en, badge.es)) are sed-unsafe but AST-safe — the codemod handles them automatically.Test plan
npx tsc --noEmit— cleannpx eslint . --ext .ts,.tsx— 11 errors / 27 warnings, identical toorigin/mainbaseline; zero new issuesnpx vitest run— 155 passed / 156 total (only pre-existinguseJournal startFreeWritefails; confirmed unchanged on main)LanguageContexttests pass under the new signaturesscripts/codemod-t-object-form.mjsfor future similar refactorsCodemod notes
ts.createSourceFile+ AST walk +getStart/getEndtext-range edits)t/bilingualfromuseLanguage()are touchedLanguageContext.test.tsxuseresult.current.t(...)member-access — the AST walker's identifier matcher doesn't catch these; updated manually🤖 Generated with Claude Code