You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 94295e2
Browse filesBrowse the repository at this point in the historyBrowse files
refactor(i18n): expose translation keys to static analysis (#865)
## Summary
- Replace finite translation-key data flows with semantic values
resolved through literal translation calls at presentation boundaries.
- Remove stale and unreachable locale entries, including the
non-actionable NONE remediation copy.
- Make the i18n check fail on missing, incomplete, or unused
translations without preservation patterns or a usage manifest.
- Add mapping tests and document the translation-key architecture in
repository guidance.
## Verification
- npm run lint passes with zero errors and twelve pre-existing warnings.
- npm run typecheck passes.
- npm run test:i18n passes with 1,128 keys and zero unused keys.
- npm run test:ci passes with 231 suites and 2,596 tests passing.
- npm run test:scripts passes with 28 suites and 189 tests passing.
- A temporary unused translation probe caused the strict i18n check to
fail and was removed afterward.
Copy file name to clipboardExpand all lines: AGENTS.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ Keep this file to repository-specific behavior and safeguards. Agent tooling is
7
7
- Standard checks are `npm run lint`, `npm run typecheck`, `npm run test:ci`, and `npm run test:scripts`.
8
8
- Before committing JavaScript or TypeScript, run `npx eslint` on the staged JS/TS files. Errors block; warnings do not.
9
9
-`i18next/no-literal-string` is an error. Put user-facing copy in translations. For technical literals, use a narrowly scoped disable with a reason; never exclude a mixed-copy file.
10
+
- Keep finite translation choices statically visible: state, props, helpers, and option metadata carry semantic values, while the nearest presentation boundary maps them through literal `t('namespace:key')` calls. Do not pass translation keys as application data or hide them with `preservePatterns` or artificial usage manifests; `npm run test:i18n` uses `i18next-cli status` and `status --unused` to reject missing, incomplete, and stale keys.
Copy file name to clipboardExpand all lines: CLAUDE.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,6 +94,33 @@ One gap the rule still has: a **module-scope** `const` is not inspected, only fu
94
94
95
95
---
96
96
97
+
## Keep Translation Keys at the Presentation Boundary
98
+
99
+
For a finite domain, application state and data carry semantic values, not i18next keys. Resolve the semantic value with an exhaustive switch whose branches call literal `t('namespace:key')` expressions at the nearest presentation boundary.
100
+
101
+
```tsx
102
+
// bad — the analyzer loses the real usage across metadata, state, and props
// good — state remains semantic and every real key is visible in the AST
108
+
function getSortOrderLabel(order:'newest'|'oldest', t:TFunction<'servers'>) {
109
+
switch (order) {
110
+
case'newest':
111
+
returnt('filter.newestFirst')
112
+
case'oldest':
113
+
returnt('filter.oldestFirst')
114
+
}
115
+
}
116
+
```
117
+
118
+
Apply the same rule to helper return values, component props, arrays, and generic option records. Keep localization out of domain/business helpers; put the exhaustive translation resolver in the nearest UI utility or component and call it during render so language changes remain reactive.
119
+
120
+
Do not use `preservePatterns`, wildcard preservation, fake or unreachable `t()` calls, comment-only extraction, or a static-usage manifest to compensate for finite-key indirection. Those mechanisms can make stale keys look used. `npm run test:i18n` runs both `i18next-cli status` and `status --unused`, so missing, incomplete, and genuinely unused locale entries must continue to fail CI. See [`docs/followups/mobile/09-i18n-guardrails.md`](./docs/followups/mobile/09-i18n-guardrails.md).
121
+
122
+
---
123
+
97
124
## No `unknown` or `any` Without Explicit Permission
98
125
99
126
Never introduce `unknown` or `any` in new code without the user's explicit approval. If a type boundary genuinely requires one, stop and ask — don't default to it as a workaround for a type error.
0 commit comments