chore(testapps/react): demonstrate typed namespace constants#3521
chore(testapps/react): demonstrate typed namespace constants#3521bdshadow wants to merge 1 commit into
Conversation
Showcase the `const NS = { ... } as const` pattern that the tolgee-cli
extractor now resolves within a single file. Namespaces.tsx declares
NS inline so extraction works; src/i18n/namespaces.ts holds the shared
authoritative list for runtime use (cross-file extractor resolution is
not yet supported).
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The React testapp uses bare string literals for translation namespaces:
That's fine in isolation but it doesn't model what most production
codebases want: a single typed source of truth for namespace
identifiers. The companion tolgee-cli PR
(tolgee/tolgee-cli#202) makes the extractor
able to resolve
const NS = { ... } as constreferences — this PRdemonstrates the recommended shape in the testapp.
Solution
testapps/react/src/i18n/namespaces.tsexportingNS = { NAMESPACED: 'namespaced' } as const— the authoritativeshared list, intended for runtime use across components.
Namespaces.tsxto declare a mirroring inlineconst NS = { NAMESPACED: 'namespaced' } as constand useNS.NAMESPACEDfor bothuseTranslate(...)and<T ns={...}>.The inline declaration is a deliberate workaround: the extractor's
const resolution is same-file only today, so importing from
i18n/namespaces.tswould still triggerW_DYNAMIC_NAMESPACE. Afollow-up extending tolgee-cli to follow imports would let consumers
drop the inline mirror.
Verification
cd testapps/react && npx tsc --noEmit— clean.against
Namespaces.tsxextracts 3 keys with namespacenamespacedand emits zero warnings.Test plan
cd testapps/react && npm run developrenders the Namespacespanel correctly.
drop the inline mirror and import
NSfrom../i18n/namespacesinstead.Companion PR