translate-kit 0.3.1 → 0.4.1
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 +100 -90
- package/dist/cli.js +2816 -457
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -4,40 +4,28 @@ AI-powered i18n for your codebase. Scan, transform, and translate — at build t
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/translate-kit)
|
|
6
6
|
[](LICENSE)
|
|
7
|
-
[](https://github.com/guillermolg00/translate-kit/actions/workflows/ci.yml)
|
|
8
7
|
|
|
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/).
|
|
8
|
+
In 2026, manually writing i18n JSON files key by key is obsolete. translate-kit is a CLI that handles the entire translation pipeline at build time: it 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
9
|
|
|
11
|
-
**
|
|
10
|
+
**Zero runtime cost. Zero lock-in.** translate-kit is not a runtime dependency. It generates standard next-intl code and JSON files. If you remove it tomorrow, your app keeps working exactly the same.
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Features
|
|
12
|
+
**[Documentation](https://translate-kit.com/docs)** · **[Blog](https://translate-kit.com/blog)** · **[Getting Started](https://translate-kit.com/docs/getting-started)**
|
|
16
13
|
|
|
17
|
-
|
|
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>`)
|
|
23
|
-
- **next-intl ready** — generates `useTranslations`-compatible message files
|
|
14
|
+
---
|
|
24
15
|
|
|
25
16
|
## Quick Start
|
|
26
17
|
|
|
27
18
|
```bash
|
|
28
|
-
# Install
|
|
29
|
-
|
|
19
|
+
# Install
|
|
20
|
+
npm install translate-kit @ai-sdk/openai
|
|
30
21
|
|
|
31
|
-
# Interactive setup
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# Translate
|
|
35
|
-
bunx translate-kit translate
|
|
22
|
+
# Interactive setup — scaffolds config, installs next-intl, runs the full pipeline
|
|
23
|
+
npx translate-kit init
|
|
36
24
|
```
|
|
37
25
|
|
|
38
|
-
The `init` wizard creates your config, sets up locales, and optionally
|
|
26
|
+
That's it. The `init` wizard creates your config, sets up locales, and optionally scans + transforms + translates your entire codebase in one step.
|
|
39
27
|
|
|
40
|
-
> See the full [Getting Started](https://translate-kit.com/docs/getting-started) guide for detailed setup
|
|
28
|
+
> See the full [Getting Started](https://translate-kit.com/docs/getting-started) guide for detailed setup.
|
|
41
29
|
|
|
42
30
|
## How It Works
|
|
43
31
|
|
|
@@ -47,11 +35,61 @@ scan → codegen → translate
|
|
|
47
35
|
|
|
48
36
|
| Step | What it does |
|
|
49
37
|
|------|-------------|
|
|
50
|
-
| **scan** | Parses JSX/TSX
|
|
51
|
-
| **codegen** | Replaces hardcoded strings with `t("key")` calls or `<T>`
|
|
52
|
-
| **translate** | Diffs source messages against lock file,
|
|
38
|
+
| **scan** | Parses JSX/TSX with Babel, extracts translatable strings (text, attributes, template literals, ternaries), generates semantic keys via AI |
|
|
39
|
+
| **codegen** | Replaces hardcoded strings with `t("key")` calls or `<T>` wrappers, injects imports and hooks, detects server/client components |
|
|
40
|
+
| **translate** | Diffs source messages against a lock file (SHA-256 hashes), only sends new/modified keys to the AI, writes target locale files |
|
|
41
|
+
|
|
42
|
+
Run the full pipeline with one command:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx translate-kit run
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or use each step independently. `translate` is the most common standalone command — write your source messages manually and let translate-kit handle the rest.
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
### Build-time, not runtime
|
|
53
|
+
|
|
54
|
+
Translation happens before your app ships. No client-side SDK, no loading spinners, no flash of untranslated content. The output is static JSON files that next-intl reads at render time.
|
|
55
|
+
|
|
56
|
+
### Any AI provider
|
|
57
|
+
|
|
58
|
+
Works with any [Vercel AI SDK](https://sdk.vercel.ai/) provider. You pick the model, you control the cost.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm install @ai-sdk/openai # OpenAI
|
|
62
|
+
npm install @ai-sdk/anthropic # Anthropic
|
|
63
|
+
npm install @ai-sdk/google # Google
|
|
64
|
+
npm install @ai-sdk/mistral # Mistral
|
|
65
|
+
npm install @ai-sdk/groq # Groq
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { openai } from "@ai-sdk/openai"; // model: openai("gpt-4o-mini")
|
|
70
|
+
import { anthropic } from "@ai-sdk/anthropic"; // model: anthropic("claude-sonnet-4-20250514")
|
|
71
|
+
import { google } from "@ai-sdk/google"; // model: google("gemini-2.0-flash")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Incremental by default
|
|
75
|
+
|
|
76
|
+
A `.translate-lock.json` file tracks SHA-256 hashes of every source value. Re-runs only translate what changed. Costs stay predictable.
|
|
77
|
+
|
|
78
|
+
### Smart extraction
|
|
79
|
+
|
|
80
|
+
The scanner parses your AST and understands which strings are user-facing text vs. code artifacts (CSS classes, URLs, constants). It extracts JSX text, attributes, template literals, conditional expressions, and object properties automatically.
|
|
53
81
|
|
|
54
|
-
|
|
82
|
+
### Namespace scoping
|
|
83
|
+
|
|
84
|
+
Codegen detects when all keys in a component share the same prefix and generates `useTranslations("hero")` instead of `useTranslations()`. Keys are stripped to their local form: `t("welcome")` instead of `t("hero.welcome")`. This lets next-intl tree-shake messages per component.
|
|
85
|
+
|
|
86
|
+
### Selective client payload
|
|
87
|
+
|
|
88
|
+
The generated layout only sends namespaces used by client components to `NextIntlClientProvider`. If your app has 20 namespaces but only 4 are used in client components, the client bundle shrinks proportionally.
|
|
89
|
+
|
|
90
|
+
### Type safety
|
|
91
|
+
|
|
92
|
+
Enable `typeSafe: true` and translate-kit auto-generates a `next-intl.d.ts` file on every scan — full autocomplete and compile-time validation for all message keys.
|
|
55
93
|
|
|
56
94
|
## Configuration
|
|
57
95
|
|
|
@@ -65,23 +103,30 @@ export default defineConfig({
|
|
|
65
103
|
sourceLocale: "en",
|
|
66
104
|
targetLocales: ["es", "fr", "de", "ja"],
|
|
67
105
|
messagesDir: "./messages",
|
|
106
|
+
splitByNamespace: true,
|
|
107
|
+
typeSafe: true,
|
|
108
|
+
translation: {
|
|
109
|
+
context: "SaaS application for project management",
|
|
110
|
+
glossary: { "Acme": "Acme" },
|
|
111
|
+
tone: "professional",
|
|
112
|
+
},
|
|
68
113
|
});
|
|
69
114
|
```
|
|
70
115
|
|
|
71
|
-
> See the
|
|
116
|
+
> See the [Configuration reference](https://translate-kit.com/docs/configuration) for all options.
|
|
72
117
|
|
|
73
118
|
## Two Modes
|
|
74
119
|
|
|
75
120
|
### Keys mode (default)
|
|
76
121
|
|
|
77
|
-
|
|
122
|
+
Strings are replaced with `t("key")` calls. Source text moves to JSON files.
|
|
78
123
|
|
|
79
124
|
```tsx
|
|
80
125
|
// Before
|
|
81
126
|
<h1>Welcome back</h1>
|
|
82
127
|
|
|
83
128
|
// After
|
|
84
|
-
<h1>{t("
|
|
129
|
+
<h1>{t("welcomeBack")}</h1>
|
|
85
130
|
```
|
|
86
131
|
|
|
87
132
|
### Inline mode
|
|
@@ -96,92 +141,57 @@ Source text stays visible in your code. A `<T>` component handles runtime resolu
|
|
|
96
141
|
<h1><T id="hero.welcomeBack">Welcome back</T></h1>
|
|
97
142
|
```
|
|
98
143
|
|
|
99
|
-
> See the [Inline Mode](https://translate-kit.com/docs/guides/inline-mode) guide for setup
|
|
100
|
-
|
|
101
|
-
## AI Providers
|
|
102
|
-
|
|
103
|
-
Any [Vercel AI SDK](https://sdk.vercel.ai/) provider works. Install the provider package and set your API key:
|
|
104
|
-
|
|
105
|
-
```bash
|
|
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
|
|
111
|
-
```
|
|
112
|
-
|
|
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
|
-
```
|
|
118
|
-
|
|
119
|
-
> See the [AI Providers](https://translate-kit.com/docs/guides/providers) guide for all providers and recommended models.
|
|
144
|
+
> See the [Inline Mode](https://translate-kit.com/docs/guides/inline-mode) guide for setup.
|
|
120
145
|
|
|
121
146
|
## Commands
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
### `translate-kit scan`
|
|
148
|
+
| Command | Description |
|
|
149
|
+
|---------|-------------|
|
|
150
|
+
| `translate-kit init` | Interactive setup wizard |
|
|
151
|
+
| `translate-kit run` | Full pipeline: scan + codegen + translate |
|
|
152
|
+
| `translate-kit scan` | Extract strings and generate keys |
|
|
153
|
+
| `translate-kit codegen` | Replace strings with i18n calls |
|
|
154
|
+
| `translate-kit translate` | Translate to target locales (incremental) |
|
|
155
|
+
| `translate-kit typegen` | Generate TypeScript types for keys |
|
|
132
156
|
|
|
133
|
-
|
|
157
|
+
All commands support `--dry-run` to preview changes and `--verbose` for detailed output. `translate` and `run` support `--force` to ignore the cache.
|
|
134
158
|
|
|
135
|
-
|
|
136
|
-
bunx translate-kit scan # Scan and generate keys
|
|
137
|
-
bunx translate-kit scan --dry-run # Preview found strings
|
|
138
|
-
```
|
|
159
|
+
> See the [Commands](https://translate-kit.com/docs/commands/init) documentation for flags and examples.
|
|
139
160
|
|
|
140
|
-
|
|
161
|
+
## Per-Namespace Splitting
|
|
141
162
|
|
|
142
|
-
|
|
163
|
+
With `splitByNamespace: true`, messages are written as individual files instead of one monolithic JSON:
|
|
143
164
|
|
|
144
|
-
```bash
|
|
145
|
-
bunx translate-kit codegen # Transform source files
|
|
146
|
-
bunx translate-kit codegen --dry-run # Preview changes
|
|
147
165
|
```
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
Translates messages to all target locales. Only new or modified keys are sent to the AI.
|
|
152
|
-
|
|
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
|
|
166
|
+
messages/en/hero.json → { "welcome": "Welcome", "getStarted": "Get started" }
|
|
167
|
+
messages/en/common.json → { "save": "Save", "cancel": "Cancel" }
|
|
168
|
+
messages/en/auth.json → { "signIn": "Sign in", "signOut": "Sign out" }
|
|
158
169
|
```
|
|
159
170
|
|
|
160
|
-
|
|
171
|
+
This enables granular code-splitting and keeps diffs clean.
|
|
161
172
|
|
|
162
|
-
##
|
|
173
|
+
## Current Limitations
|
|
163
174
|
|
|
164
|
-
|
|
175
|
+
translate-kit handles around 95% of translatable content in a typical codebase. Patterns not yet supported:
|
|
165
176
|
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
- **Removed** — keys no longer in source, cleaned up
|
|
177
|
+
- Strings in standalone variables and constants (`const title = "Welcome"`)
|
|
178
|
+
- Non-JSX files (API responses, error messages in plain `.ts` files)
|
|
179
|
+
- Currently next-intl / Next.js only — other i18n runtimes are on the roadmap
|
|
170
180
|
|
|
171
|
-
|
|
181
|
+
For these cases, add keys manually to your source locale JSON and translate-kit will translate them along with everything else.
|
|
172
182
|
|
|
173
|
-
> See the [
|
|
183
|
+
> See the [full limitations page](https://translate-kit.com/docs/technical/limitations) for details.
|
|
174
184
|
|
|
175
185
|
## Documentation
|
|
176
186
|
|
|
177
|
-
Full documentation
|
|
187
|
+
Full documentation at **[translate-kit.com](https://translate-kit.com/docs)**.
|
|
178
188
|
|
|
179
189
|
- [Getting Started](https://translate-kit.com/docs/getting-started)
|
|
180
190
|
- [Configuration](https://translate-kit.com/docs/configuration)
|
|
181
191
|
- [AI Providers](https://translate-kit.com/docs/guides/providers)
|
|
182
192
|
- [Inline Mode](https://translate-kit.com/docs/guides/inline-mode)
|
|
183
|
-
- [Incremental Translations](https://translate-kit.com/docs/guides/incremental)
|
|
184
193
|
- [next-intl Integration](https://translate-kit.com/docs/guides/next-intl)
|
|
194
|
+
- [Architecture](https://translate-kit.com/docs/technical/architecture)
|
|
185
195
|
|
|
186
196
|
## License
|
|
187
197
|
|