feat(i18n): add translator context for AI message catalog - #2983
Conversation
Add en.context.json with usage context for every English key and pass it to the translation worker prompt so Workers AI can disambiguate short UI labels. Checksum now includes contexts so catalog refreshes pick this up. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
🔗 Linked repositories identifiedCodeRabbit considers these linked repositories for cross-repo context during reviews:
📝 WalkthroughWalkthroughThe PR generates English translation contexts from source usage, stores them separately, includes them in translation checksums and batches, and sends structured text/context payloads to Workers AI. Tests validate context coverage, payload serialization, and prompt instructions. ChangesTranslation context pipeline
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SourceFiles
participant ContextGenerator
participant TranslationWorker
participant WorkersAI
ContextGenerator->>SourceFiles: discover translation-key usage
SourceFiles-->>ContextGenerator: return keys and source locations
ContextGenerator->>TranslationWorker: provide generated context catalog
TranslationWorker->>WorkersAI: send structured text/context batches
WorkersAI-->>TranslationWorker: return translated text
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
Stale comment
Risk: medium. Left a non-blocking comment — Bugbot passed with no findings, but this changes the Cloudflare and backend translation pipelines plus catalog checksum invalidation, so it is above the low-risk auto-approve threshold. Human review is needed; assigning reviewers.
Sent by Cursor Approval Agent: Pull Request Approver External
Widen UsersQueryResult mocks so resolved user rows typecheck under tsgo. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
There was a problem hiding this comment.
Stale comment
Risk: medium. Left a non-blocking comment — Bugbot passed with no findings, but this changes the Cloudflare and backend translation pipelines plus catalog checksum invalidation, so it is above the low-risk auto-approve threshold. Human review is needed; reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@messages/README.md`:
- Around line 12-14: Update the documented translation-context generation
command near generate-translation-contexts.mjs to use the package script entry
point, bun run i18n:contexts, instead of invoking Node directly.
In `@scripts/generate-translation-contexts.mjs`:
- Line 11: In the directory traversal loop using readdirSync(dir), sort the
returned entries before iteration, and sort each filesForKey collection before
selecting its first five locations. Preserve the existing selection logic while
ensuring generated contexts and checksum-based cache inputs are deterministic.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 9091d600-f189-4cb0-94f9-66dc9bf79776
📒 Files selected for processing (8)
cloudflare_workers/translation/index.tsmessages/README.mdmessages/en.context.jsonpackage.jsonscripts/generate-translation-contexts.mjssupabase/functions/_backend/public/translation.tstests/email-preferences-public.unit.test.tstests/translation-queue.unit.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
There was a problem hiding this comment.
Review completed against the latest diff
Not reviewed (too large): messages/en.context.json (~2,719 lines) - if these are generated or fixture files, add them to ignored paths to exclude them from future reviews.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
Use bun run i18n:contexts in docs, make context generation deterministic, and store folder-based areas instead of file names so renames do not churn translation checksums. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/generate-translation-contexts.mjs`:
- Around line 73-78: Update the area derivation logic in the translation-context
generation flow so root-level files under src/ also remove their filename before
building the area. Ensure the resulting empty path uses the existing 'app'
fallback, keeping contexts stable when files such as App.vue are renamed.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 263eddb4-2a39-4152-9067-e8258e0a35ed
📒 Files selected for processing (6)
cloudflare_workers/translation/index.tsmessages/README.mdmessages/en.context.jsonscripts/generate-translation-contexts.mjssupabase/functions/_backend/public/translation.tstests/translation-queue.unit.test.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
Cap-go/capacitor-updater(manual)
Map src root files to the app area fallback so renames like App.vue do not churn translation checksums. Co-authored-by: Martin DONADIEU <martindonadieu@gmail.com>
There was a problem hiding this comment.
Risk: medium. Left a non-blocking comment — Bugbot passed with no findings, but this changes the Cloudflare and backend translation pipelines plus catalog checksum invalidation, so it is above the low-risk auto-approve threshold. Human review is needed; reviewers are already assigned.
Sent by Cursor Approval Agent: Pull Request Approver External
|





Summary (AI generated)
messages/en.context.jsonwith usage context for every English i18n key (2717 keys).{ text, context }to Workers AI and instruct it to use context for disambiguation.bun run i18n:contextsto regenerate contexts from code usages.Motivation (AI generated)
Short UI strings like "Current", "Access", or "Filters" were being mistranslated because the automation worker only saw bare English text. Inlang message-format cannot store translator notes inside
en.json(values must be strings), so a companion context file is required.Business Impact (AI generated)
Better non-English console UX with fewer wrong word senses, without changing the public Vue i18n API or requiring manual per-locale catalogs.
Test Plan (AI generated)
bunx vitest run tests/translation-queue.unit.test.tsbun run typecheck:backendbunx vitest run tests/email-preferences-public.unit.test.tsbun run i18n:contextsregenCurrent,Filters,MAU) in a translated catalogGenerated with AI
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
New Features
Documentation
Tests