translate-kit 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -82
- package/dist/cli.js +1564 -774
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,37 +1,58 @@
|
|
|
1
1
|
# translate-kit
|
|
2
2
|
|
|
3
|
-
AI-powered
|
|
3
|
+
AI-powered i18n for your codebase. Scan, transform, and translate — at build time.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/translate-kit)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://github.com/guillermolg00/translate-kit/actions/workflows/ci.yml)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
translate-kit extracts translatable strings from your JSX/TSX, generates semantic keys with AI, replaces hardcoded text with i18n calls, and translates everything to your target locales — using your own AI models via [Vercel AI SDK](https://sdk.vercel.ai/). Compatible with [next-intl](https://next-intl.dev/).
|
|
10
|
+
|
|
11
|
+
**[Documentation](https://translate-kit.com/docs)** · **[Getting Started](https://translate-kit.com/docs/getting-started)** · **[Configuration](https://translate-kit.com/docs/configuration)**
|
|
12
|
+
|
|
13
|
+
---
|
|
10
14
|
|
|
11
15
|
## Features
|
|
12
16
|
|
|
13
|
-
- **Build-time AI translation** —
|
|
14
|
-
- **Incremental** —
|
|
15
|
-
- **Any provider** — OpenAI, Anthropic, Google, Mistral, Groq, or any Vercel AI SDK provider
|
|
16
|
-
- **Scanner** — extract translatable strings from JSX/TSX
|
|
17
|
-
- **Codegen** — replace hardcoded strings with `t()` calls
|
|
17
|
+
- **Build-time AI translation** — no runtime overhead, translations are generated at build time
|
|
18
|
+
- **Incremental** — lock file tracks source hashes, re-runs only translate what changed
|
|
19
|
+
- **Any AI provider** — OpenAI, Anthropic, Google, Mistral, Groq, or any Vercel AI SDK provider
|
|
20
|
+
- **Scanner** — extract translatable strings from JSX/TSX using Babel AST analysis
|
|
21
|
+
- **Codegen** — replace hardcoded strings with `t()` calls or `<T>` components automatically
|
|
22
|
+
- **Two modes** — keys mode (`t("key")`) or inline mode (`<T id="key">text</T>`)
|
|
18
23
|
- **next-intl ready** — generates `useTranslations`-compatible message files
|
|
19
24
|
|
|
20
25
|
## Quick Start
|
|
21
26
|
|
|
22
27
|
```bash
|
|
23
|
-
# Install
|
|
24
|
-
npm install translate-kit @ai-sdk/openai
|
|
25
|
-
# or
|
|
28
|
+
# Install translate-kit and an AI provider
|
|
26
29
|
bun add translate-kit @ai-sdk/openai
|
|
27
30
|
|
|
28
|
-
#
|
|
29
|
-
|
|
31
|
+
# Interactive setup
|
|
32
|
+
bunx translate-kit init
|
|
30
33
|
|
|
31
34
|
# Translate
|
|
32
|
-
|
|
35
|
+
bunx translate-kit translate
|
|
33
36
|
```
|
|
34
37
|
|
|
38
|
+
The `init` wizard creates your config, sets up locales, and optionally runs the full pipeline.
|
|
39
|
+
|
|
40
|
+
> See the full [Getting Started](https://translate-kit.com/docs/getting-started) guide for detailed setup instructions.
|
|
41
|
+
|
|
42
|
+
## How It Works
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
scan → codegen → translate
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| Step | What it does |
|
|
49
|
+
|------|-------------|
|
|
50
|
+
| **scan** | Parses JSX/TSX files, extracts translatable strings, generates semantic keys via AI |
|
|
51
|
+
| **codegen** | Replaces hardcoded strings with `t("key")` calls or `<T>` components, injects imports |
|
|
52
|
+
| **translate** | Diffs source messages against lock file, translates only new/modified keys |
|
|
53
|
+
|
|
54
|
+
You can use any step independently. The `translate` command is the most commonly used on its own — write your source messages and let translate-kit handle the rest.
|
|
55
|
+
|
|
35
56
|
## Configuration
|
|
36
57
|
|
|
37
58
|
```ts
|
|
@@ -42,113 +63,125 @@ import { openai } from "@ai-sdk/openai";
|
|
|
42
63
|
export default defineConfig({
|
|
43
64
|
model: openai("gpt-4o-mini"),
|
|
44
65
|
sourceLocale: "en",
|
|
45
|
-
targetLocales: ["es", "fr", "de"],
|
|
66
|
+
targetLocales: ["es", "fr", "de", "ja"],
|
|
46
67
|
messagesDir: "./messages",
|
|
47
|
-
|
|
48
|
-
translation: {
|
|
49
|
-
batchSize: 50,
|
|
50
|
-
concurrency: 3,
|
|
51
|
-
context: "SaaS application for project management",
|
|
52
|
-
glossary: { Acme: "Acme" },
|
|
53
|
-
tone: "professional",
|
|
54
|
-
retries: 2,
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
scan: {
|
|
58
|
-
include: ["src/**/*.tsx", "app/**/*.tsx"],
|
|
59
|
-
exclude: ["**/*.test.*"],
|
|
60
|
-
keyStrategy: "hash",
|
|
61
|
-
translatableProps: ["placeholder", "title", "alt", "aria-label"],
|
|
62
|
-
i18nImport: "next-intl",
|
|
63
|
-
},
|
|
64
68
|
});
|
|
65
69
|
```
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
> See the full [Configuration reference](https://translate-kit.com/docs/configuration) for all options including translation context, glossary, tone, batching, and scanner settings.
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
## Two Modes
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
### Keys mode (default)
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
Hardcoded strings are replaced with `t("key")` calls. Source text lives in JSON files.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
// Before
|
|
81
|
+
<h1>Welcome back</h1>
|
|
82
|
+
|
|
83
|
+
// After
|
|
84
|
+
<h1>{t("hero.welcomeBack")}</h1>
|
|
79
85
|
```
|
|
80
86
|
|
|
81
|
-
###
|
|
87
|
+
### Inline mode
|
|
82
88
|
|
|
83
|
-
|
|
89
|
+
Source text stays visible in your code. A `<T>` component handles runtime resolution.
|
|
84
90
|
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
```tsx
|
|
92
|
+
// Before
|
|
93
|
+
<h1>Welcome back</h1>
|
|
94
|
+
|
|
95
|
+
// After
|
|
96
|
+
<h1><T id="hero.welcomeBack">Welcome back</T></h1>
|
|
88
97
|
```
|
|
89
98
|
|
|
90
|
-
|
|
99
|
+
> See the [Inline Mode](https://translate-kit.com/docs/guides/inline-mode) guide for setup and usage.
|
|
91
100
|
|
|
92
|
-
|
|
101
|
+
## AI Providers
|
|
102
|
+
|
|
103
|
+
Any [Vercel AI SDK](https://sdk.vercel.ai/) provider works. Install the provider package and set your API key:
|
|
93
104
|
|
|
94
105
|
```bash
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
bun add @ai-sdk/openai # OpenAI
|
|
107
|
+
bun add @ai-sdk/anthropic # Anthropic
|
|
108
|
+
bun add @ai-sdk/google # Google
|
|
109
|
+
bun add @ai-sdk/mistral # Mistral
|
|
110
|
+
bun add @ai-sdk/groq # Groq
|
|
97
111
|
```
|
|
98
112
|
|
|
99
|
-
|
|
113
|
+
```ts
|
|
114
|
+
import { openai } from "@ai-sdk/openai"; // model: openai("gpt-4o-mini")
|
|
115
|
+
import { anthropic } from "@ai-sdk/anthropic"; // model: anthropic("claude-sonnet-4-20250514")
|
|
116
|
+
import { google } from "@ai-sdk/google"; // model: google("gemini-2.0-flash")
|
|
117
|
+
```
|
|
100
118
|
|
|
101
|
-
|
|
119
|
+
> See the [AI Providers](https://translate-kit.com/docs/guides/providers) guide for all providers and recommended models.
|
|
102
120
|
|
|
103
|
-
##
|
|
121
|
+
## Commands
|
|
104
122
|
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
### `translate-kit init`
|
|
124
|
+
|
|
125
|
+
Interactive setup wizard. Creates config, scaffolds i18n integration, and optionally runs the full pipeline.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
bunx translate-kit init
|
|
107
129
|
```
|
|
108
130
|
|
|
109
|
-
|
|
110
|
-
2. **Codegen** — replace hardcoded strings with `t("key")` calls, add `useTranslations` imports and hooks
|
|
111
|
-
3. **Translate** — diff source messages against lock file, translate only new/modified keys, write target locale JSONs
|
|
131
|
+
### `translate-kit scan`
|
|
112
132
|
|
|
113
|
-
|
|
133
|
+
Extracts translatable strings from your source code and generates semantic keys with AI.
|
|
114
134
|
|
|
115
|
-
|
|
135
|
+
```bash
|
|
136
|
+
bunx translate-kit scan # Scan and generate keys
|
|
137
|
+
bunx translate-kit scan --dry-run # Preview found strings
|
|
138
|
+
```
|
|
116
139
|
|
|
117
|
-
translate-kit
|
|
140
|
+
### `translate-kit codegen`
|
|
118
141
|
|
|
119
|
-
|
|
120
|
-
import { openai } from "@ai-sdk/openai";
|
|
121
|
-
import { anthropic } from "@ai-sdk/anthropic";
|
|
122
|
-
import { google } from "@ai-sdk/google";
|
|
123
|
-
import { mistral } from "@ai-sdk/mistral";
|
|
142
|
+
Replaces hardcoded strings with i18n calls and injects imports/hooks.
|
|
124
143
|
|
|
125
|
-
|
|
126
|
-
|
|
144
|
+
```bash
|
|
145
|
+
bunx translate-kit codegen # Transform source files
|
|
146
|
+
bunx translate-kit codegen --dry-run # Preview changes
|
|
147
|
+
```
|
|
127
148
|
|
|
128
|
-
|
|
129
|
-
model: anthropic("claude-sonnet-4-20250514")
|
|
149
|
+
### `translate-kit translate`
|
|
130
150
|
|
|
131
|
-
|
|
132
|
-
model: google("gemini-2.0-flash")
|
|
151
|
+
Translates messages to all target locales. Only new or modified keys are sent to the AI.
|
|
133
152
|
|
|
134
|
-
|
|
135
|
-
|
|
153
|
+
```bash
|
|
154
|
+
bunx translate-kit translate # Translate all locales
|
|
155
|
+
bunx translate-kit translate --locale es # Only Spanish
|
|
156
|
+
bunx translate-kit translate --dry-run # Preview what would be translated
|
|
157
|
+
bunx translate-kit translate --force # Ignore cache, re-translate everything
|
|
136
158
|
```
|
|
137
159
|
|
|
138
|
-
|
|
160
|
+
> See the [Commands](https://translate-kit.com/docs/commands/init) documentation for detailed usage and flags.
|
|
161
|
+
|
|
162
|
+
## Incremental Translations
|
|
163
|
+
|
|
164
|
+
A `.translate-lock.json` file stores SHA-256 hashes of source values. On each run, translate-kit computes a diff:
|
|
165
|
+
|
|
166
|
+
- **Added** — new keys, not yet translated
|
|
167
|
+
- **Modified** — source text changed since last translation
|
|
168
|
+
- **Unchanged** — hash matches, skipped
|
|
169
|
+
- **Removed** — keys no longer in source, cleaned up
|
|
139
170
|
|
|
140
|
-
|
|
171
|
+
Only added and modified keys are sent to the AI. This keeps API calls fast and costs low.
|
|
141
172
|
|
|
142
|
-
-
|
|
143
|
-
- **JSX attributes** — `<input placeholder="Enter name" />`
|
|
144
|
-
- **Expression containers** — `<div>{"Hello"}</div>`
|
|
145
|
-
- **Object properties** — `{ title: "Dashboard" }`
|
|
173
|
+
> See the [Incremental Translations](https://translate-kit.com/docs/guides/incremental) guide for details.
|
|
146
174
|
|
|
147
|
-
|
|
175
|
+
## Documentation
|
|
148
176
|
|
|
149
|
-
|
|
177
|
+
Full documentation is available at **[translate-kit.com](https://translate-kit.com/docs)**.
|
|
150
178
|
|
|
151
|
-
|
|
179
|
+
- [Getting Started](https://translate-kit.com/docs/getting-started)
|
|
180
|
+
- [Configuration](https://translate-kit.com/docs/configuration)
|
|
181
|
+
- [AI Providers](https://translate-kit.com/docs/guides/providers)
|
|
182
|
+
- [Inline Mode](https://translate-kit.com/docs/guides/inline-mode)
|
|
183
|
+
- [Incremental Translations](https://translate-kit.com/docs/guides/incremental)
|
|
184
|
+
- [next-intl Integration](https://translate-kit.com/docs/guides/next-intl)
|
|
152
185
|
|
|
153
186
|
## License
|
|
154
187
|
|