Skip to content

chore(testapps/react): demonstrate typed namespace constants#3521

Draft
bdshadow wants to merge 1 commit into
mainfrom
bdshadow/namespace-demo
Draft

chore(testapps/react): demonstrate typed namespace constants#3521
bdshadow wants to merge 1 commit into
mainfrom
bdshadow/namespace-demo

Conversation

@bdshadow

Copy link
Copy Markdown
Member

Problem

The React testapp uses bare string literals for translation namespaces:

const { t } = useTranslate('namespaced');
<T keyName="this_is_a_key" ns="namespaced" />

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 const references — this PR
demonstrates the recommended shape in the testapp.

Solution

  • New testapps/react/src/i18n/namespaces.ts exporting
    NS = { NAMESPACED: 'namespaced' } as const — the authoritative
    shared list, intended for runtime use across components.
  • Updated Namespaces.tsx to declare a mirroring inline
    const NS = { NAMESPACED: 'namespaced' } as const and use
    NS.NAMESPACED for both useTranslate(...) 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.ts would still trigger W_DYNAMIC_NAMESPACE. A
follow-up extending tolgee-cli to follow imports would let consumers
drop the inline mirror.

Verification

  • cd testapps/react && npx tsc --noEmit — clean.
  • Running the tolgee-cli extractor (with the companion PR applied)
    against Namespaces.tsx extracts 3 keys with namespace
    namespaced and emits zero warnings.

Test plan

  • cd testapps/react && npm run develop renders the Namespaces
    panel correctly.
  • Once the companion tolgee-cli PR is merged and a release cut,
    drop the inline mirror and import NS from
    ../i18n/namespaces instead.

Companion PR

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).
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@bdshadow has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 37 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9725aded-143a-45db-b62e-ef9b4c09d620

📥 Commits

Reviewing files that changed from the base of the PR and between 23591f6 and d9fe041.

📒 Files selected for processing (2)
  • testapps/react/src/components/Namespaces.tsx
  • testapps/react/src/i18n/namespaces.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bdshadow/namespace-demo

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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