RFC: AI Integration in Lingui CLI #2392
andrii-bodnar
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
|
Super cool initiative!!
#: src/pages/oscar/ad-campaigns/ads.tsx:1182
msgid "Add description..."
msgstr "Beschreibung hinzufügen..."6. System Prompts: I believe that users should be able to either a) update the System prompt or b) at least inject additoinal context to the translation. What comes to mind for me is that often times there are guidelines on how a brand communicates. Being able to add such communication guidelines to the context makes the translations more precise, especially when starting from scratch. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Background
Two key pain points exist in current i18n workflows:
.pofiles.This RFC proposes native AI integration in Lingui CLI to address both issues.
Motivation
extract→translate→compilebecomes the standard flowProposed Solution
Overview
Two AI-powered features:
extract): Analyzes code surrounding each message and generates descriptive commentstranslatecommand): Fills missing translations using AIBoth features share a common AI service infrastructure.
Configuration
Add new root-level
aiconfiguration inpackages/conf/src/types.ts:Users import and configure their preferred provider directly, giving full control over provider options and supporting any AI SDK provider (including community providers).
Environment Variables
Each provider uses its own standard environment variables per Vercel AI SDK conventions:
OPENAI_API_KEY=sk-... ANTHROPIC_API_KEY=sk-ant-... GEMINI_API_KEY=... # And any other provider...Architecture
flowchart TD subgraph Extract[lingui extract] E1[Extract Messages] --> E2[Messages Collected] E2 --> E3{Context Enabled?} E3 -->|Yes| E4[AI Service: Generate Context] E3 -->|No| E5[Write Catalogs] E4 --> E5 end subgraph Translate[lingui translate] T1[Read Catalogs] --> T2[Find Missing Translations] T2 --> T3[AI Service: Generate Translations] T3 --> T4[Write Translations] end AIService[AI Service<br/>Vercel AI SDK] -.->|Context| E4 AIService -.->|Translation| T3Implementation Details
1. AI Service Module (
packages/cli/src/api/ai/)2. Core Interface:
This is a very basic example. Probably, we should stick to the Structured Output Generation approach under the hood.
3. Integration Points:
Context Generation -
packages/cli/src/api/catalog/extractFromFiles.ts:commentsfieldTranslation - New command
packages/cli/src/lingui-translate.ts:4. Using the Configured Model:
Usage Examples
1. Context Generation:
Output:
2. Automatic Translation:
Benefits
--contextfor extract, command itself for translate)Dependencies
Core dependency:
ai- Vercel AI SDK (peer dependency - users install what they need)User installs their chosen provider(s):
@ai-sdk/openai- For OpenAI models@ai-sdk/anthropic- For Anthropic models@ai-sdk/google- For Google modelsPrompt Examples
Context Generation:
Translation:
Open Questions
@lingui/ai?Beta Was this translation helpful? Give feedback.
All reactions