Skip to content

chore: dev-mode warning when i18n translation key is missing - #42

Merged
TrainTravel merged 1 commit into
mainfrom
chore/i18n-fallback-warning
May 26, 2026
Merged

chore: dev-mode warning when i18n translation key is missing#42
TrainTravel merged 1 commit into
mainfrom
chore/i18n-fallback-warning

Conversation

@TrainTravel

Copy link
Copy Markdown
Owner

Summary

Adds a dev-mode console warning whenever stringFor() falls back to the English value because a ja, zh-Hans, or zh-Hant translation key is missing. Prod behavior is byte-identical — gated on import.meta.env.DEV.

[i18n] Missing ja translation, falling back to en: "Brain Dump"

Memoized per (lang, en-value) pair so re-renders don't flood the console.

Why

The "Write today / Write today" bug (PR #39) and the Spanish-using-French-CBT bug (PR #38) and the chrome-stays-English problem (PR #36) all share one root cause: silent fallbacks hide incomplete translations. PR #39's bilingual() dedupe fixed the most visible symptom (X / X rendering). This PR adds the surveillance layer so future fallbacks are visible during development, not discovered later via a user screenshot.

Roadmap (not in this PR)

The honest end-state is to eliminate the fallback entirely:

  1. Tier 1 chrome translations — shipped in PR feat: chrome translation Tier 1 — Home + Breathe + badges (ja/zh-Hans/zh-Hant) #40
  2. Tier 2 — EmotionsScreen / Reflection / Gratitude / Feedback / BrainDump / ProgressScreen
  3. Tier 3 — long tail (settings, vocab, error messages)
  4. Once CI has been green with this dev warning for a sprint, promote the Translations type's optional ja / zh-Hans / zh-Hant keys to required. Delete the fallback branch.

Until step 4, this warning is the early-warning system.

Test plan

  • npx tsc --noEmit — clean
  • npx vitest run — 193 / 194 (only pre-existing useJournal startFreeWrite fails)
  • 5 new tests in LanguageContext.test.tsx:
    • warns for missing ja key (returns en value)
    • warns for missing zh-Hant key
    • no warn when the key is present
    • no warn for fr / en / es lookups (no fallback possible)
    • 3 lookups → 1 warning (dedupe)
  • Manual: npm run dev, open Home with target=ja, console flags every Tier-2 string that's not yet translated
  • Manual: production build (npm run build && npm run preview) — no warnings in console

🤖 Generated with Claude Code

stringFor() now logs to the dev console whenever a ja / zh-Hans /
zh-Hant translation is requested but not present on the Translations
object — making silent fallbacks visible while developing.

  [i18n] Missing ja translation, falling back to en: "Brain Dump"

Memoized per (lang, en-value) pair so re-renders don't flood the
console. Gated on import.meta.env.DEV — prod is byte-identical
behavior, no warning, no perf cost.

This is the early-warning system for the larger "kill the fallback"
goal: when Tier 2/3 chrome translations land and CI is green for a
sprint, the optional ja/zh-* keys on the Translations type get
promoted to required and the fallback branch deletes entirely.

5 new tests cover: warns for missing ja, warns for missing zh-Hant,
no warn when key present, no warn for fr/en/es, and dedupe behavior
(3 lookups → 1 warning).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TrainTravel
TrainTravel merged commit 6e042d6 into main May 26, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant