docs-i18n 0.8.1 → 0.8.2
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/admin/dist/server/server.js +20 -20
- package/package.json +1 -1
- package/template/app/utils/content-loader.ts +4 -0
- package/template/app/utils/docs.server.ts +7 -0
- package/template/content/blog/en/announcing-query-v5.md +110 -0
- package/template/content/blog/en/hello-world.md +26 -0
- package/template/content/blog/en/i18n-best-practices.md +57 -0
- package/template/content/blog/en/react-query-vs-swr.md +100 -0
- package/template/content/blog/en/state-management-2024.md +143 -0
- package/template/content/blog/en/tanstack-router-1.0.md +121 -0
- package/template/content/blog/ja/announcing-query-v5.md +110 -0
- package/template/content/blog/ja/hello-world.md +26 -0
- package/template/content/blog/zh-hans/announcing-query-v5.md +93 -0
- package/template/content/blog/zh-hans/hello-world.md +26 -0
- package/template/content/docs-i18n/docs.config.json +25 -0
- package/template/content/docs-i18n/en/architecture.md +222 -0
- package/template/content/docs-i18n/en/configuration.md +331 -0
- package/template/content/docs-i18n/en/deployment.md +209 -0
- package/template/content/docs-i18n/en/getting-started.md +168 -0
- package/template/content/docs.config.json +25 -0
- package/template/content/en/admin.md +151 -0
- package/template/content/en/architecture.md +222 -0
- package/template/content/en/cli.md +269 -0
- package/template/content/en/configuration.md +331 -0
- package/template/content/en/deployment.md +209 -0
- package/template/content/en/getting-started.md +168 -0
- package/template/content/form/docs.config.json +18 -0
- package/template/content/form/en/guides/validation.md +175 -0
- package/template/content/form/en/installation.md +63 -0
- package/template/content/form/en/overview.md +71 -0
- package/template/content/form/en/quick-start.md +121 -0
- package/template/content/form/ja/installation.md +63 -0
- package/template/content/form/ja/overview.md +71 -0
- package/template/content/form/zh-hans/installation.md +63 -0
- package/template/content/form/zh-hans/overview.md +71 -0
- package/template/content/query/docs.config.json +32 -0
- package/template/content/query/en/guides/mutations.md +126 -0
- package/template/content/query/en/guides/pagination.md +98 -0
- package/template/content/query/en/guides/queries.md +120 -0
- package/template/content/query/en/installation.md +78 -0
- package/template/content/query/en/overview.md +72 -0
- package/template/content/query/en/quick-start.md +108 -0
- package/template/content/query/ja/installation.md +78 -0
- package/template/content/query/ja/overview.md +72 -0
- package/template/content/query/zh-hans/guides/mutations.md +126 -0
- package/template/content/query/zh-hans/guides/pagination.md +98 -0
- package/template/content/query/zh-hans/guides/queries.md +120 -0
- package/template/content/query/zh-hans/installation.md +95 -0
- package/template/content/query/zh-hans/overview.md +72 -0
- package/template/content/query/zh-hans/quick-start.md +108 -0
- package/template/content/router/docs.config.json +18 -0
- package/template/content/router/en/guides/routing-concepts.md +131 -0
- package/template/content/router/en/installation.md +57 -0
- package/template/content/router/en/overview.md +74 -0
- package/template/content/router/en/quick-start.md +88 -0
- package/template/content/router/ja/installation.md +57 -0
- package/template/content/router/ja/overview.md +78 -0
- package/template/content/router/zh-hans/guides/routing-concepts.md +131 -0
- package/template/content/router/zh-hans/installation.md +57 -0
- package/template/content/router/zh-hans/overview.md +81 -0
- package/template/content/router/zh-hans/quick-start.md +88 -0
- package/template/content/table/docs.config.json +18 -0
- package/template/content/table/en/guides/column-definitions.md +135 -0
- package/template/content/table/en/installation.md +56 -0
- package/template/content/table/en/overview.md +79 -0
- package/template/content/table/en/quick-start.md +112 -0
- package/template/content/table/ja/installation.md +56 -0
- package/template/content/table/ja/overview.md +79 -0
- package/template/content/table/zh-hans/installation.md +56 -0
- package/template/content/table/zh-hans/overview.md +79 -0
- package/template/content/virtual/docs.config.json +18 -0
- package/template/content/virtual/en/guides/dynamic-sizing.md +129 -0
- package/template/content/virtual/en/installation.md +57 -0
- package/template/content/virtual/en/overview.md +74 -0
- package/template/content/virtual/en/quick-start.md +114 -0
- package/template/content/virtual/ja/installation.md +57 -0
- package/template/content/virtual/ja/overview.md +74 -0
- package/template/content/virtual/zh-hans/installation.md +57 -0
- package/template/content/virtual/zh-hans/overview.md +74 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Configuration
|
|
3
|
+
description: Complete reference for the docs-i18n configuration file and all available options.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Configuration
|
|
7
|
+
|
|
8
|
+
docs-i18n is configured via a `docs-i18n.config.ts` file in your project root. Use the `defineConfig` helper for type safety.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { defineConfig } from 'docs-i18n';
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
// ... options
|
|
15
|
+
});
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Full Config Reference
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
interface DocsI18nConfig {
|
|
22
|
+
projects: Record<string, ProjectConfig>;
|
|
23
|
+
languages: string[];
|
|
24
|
+
cacheDir?: string;
|
|
25
|
+
translatableFields?: string[];
|
|
26
|
+
include?: string[];
|
|
27
|
+
context?: string;
|
|
28
|
+
llm?: {
|
|
29
|
+
provider?: 'openrouter' | 'openai' | 'anthropic';
|
|
30
|
+
model?: string;
|
|
31
|
+
apiKey?: string;
|
|
32
|
+
contextLength?: number;
|
|
33
|
+
maxTokens?: number;
|
|
34
|
+
};
|
|
35
|
+
onTranslated?: (info: {
|
|
36
|
+
project: string;
|
|
37
|
+
version: string;
|
|
38
|
+
lang: string;
|
|
39
|
+
}) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ProjectConfig {
|
|
43
|
+
sources: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
### `projects`
|
|
50
|
+
|
|
51
|
+
**Required.** A map of project IDs to their configuration. Each project has a `sources` object mapping version names to source directories (relative to project root).
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
projects: {
|
|
55
|
+
mydocs: {
|
|
56
|
+
sources: {
|
|
57
|
+
latest: 'content/docs',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The version key (e.g., `latest`, `v1`) is used to organize translations in the cache and in assembled output. The source path points to the directory containing your English markdown/MDX files.
|
|
64
|
+
|
|
65
|
+
**Single project:**
|
|
66
|
+
|
|
67
|
+
When you have a single project, version keys are used directly in the database and output paths (e.g., `latest`).
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
projects: {
|
|
71
|
+
docs: {
|
|
72
|
+
sources: { latest: 'content/docs' },
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Multi-project:**
|
|
78
|
+
|
|
79
|
+
When you have multiple projects, keys become compound: `project/version` (e.g., `query/latest`, `table/v1`).
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
projects: {
|
|
83
|
+
query: {
|
|
84
|
+
sources: {
|
|
85
|
+
latest: 'content/query/latest',
|
|
86
|
+
v4: 'content/query/v4',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
table: {
|
|
90
|
+
sources: {
|
|
91
|
+
latest: 'content/table/latest',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
blog: {
|
|
95
|
+
sources: {
|
|
96
|
+
latest: 'content/blog',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `languages`
|
|
103
|
+
|
|
104
|
+
**Required.** An array of target language codes to translate into. These codes are used as identifiers in the cache and output directories.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
languages: ['zh-hans', 'ja', 'es', 'ko', 'fr', 'de']
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Common language codes:
|
|
111
|
+
|
|
112
|
+
| Code | Language |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `zh-hans` | Simplified Chinese |
|
|
115
|
+
| `zh-hant` | Traditional Chinese |
|
|
116
|
+
| `ja` | Japanese |
|
|
117
|
+
| `ko` | Korean |
|
|
118
|
+
| `es` | Spanish |
|
|
119
|
+
| `fr` | French |
|
|
120
|
+
| `de` | German |
|
|
121
|
+
| `pt` | Portuguese |
|
|
122
|
+
| `ru` | Russian |
|
|
123
|
+
| `ar` | Arabic |
|
|
124
|
+
| `vi` | Vietnamese |
|
|
125
|
+
| `hi` | Hindi |
|
|
126
|
+
| `th` | Thai |
|
|
127
|
+
|
|
128
|
+
### `cacheDir`
|
|
129
|
+
|
|
130
|
+
**Optional.** Directory for the SQLite cache database and assembled output. Default: `'.cache'`.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
cacheDir: '.cache'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The cache database is stored at `<cacheDir>/translations.db`. Assembled output files are written to `<cacheDir>/content/<version>/<lang>/`.
|
|
137
|
+
|
|
138
|
+
### `translatableFields`
|
|
139
|
+
|
|
140
|
+
**Optional.** Frontmatter YAML fields to translate. Supports dot notation for nested fields. Default: `['title', 'description', 'nav_title']`.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
translatableFields: ['title', 'description', 'nav_title', 'related.title', 'related.description']
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
When a frontmatter block is detected, only these fields are extracted and sent to the LLM as plain text. All other frontmatter fields are preserved unchanged. After translation, the frontmatter is reconstructed with translated values while maintaining original YAML formatting.
|
|
147
|
+
|
|
148
|
+
### `include`
|
|
149
|
+
|
|
150
|
+
**Optional.** Glob patterns for files to include. Default: `['**/*.mdx', '**/*.md']`.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
include: ['**/*.mdx', '**/*.md']
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Files not matching these patterns are ignored during scanning, translation, and assembly.
|
|
157
|
+
|
|
158
|
+
### `context`
|
|
159
|
+
|
|
160
|
+
**Optional.** Project context injected into the LLM system prompt. Use this to provide domain-specific information that helps the LLM produce better translations.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
context: 'TanStack Query is a data-fetching and state management library for React, Vue, Solid, and Angular. It was previously known as React Query.'
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
This text is appended to the system prompt under a "CONTEXT" section, giving the LLM background about your project, terminology preferences, or naming conventions.
|
|
167
|
+
|
|
168
|
+
### `llm`
|
|
169
|
+
|
|
170
|
+
**Optional.** LLM provider configuration.
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
llm: {
|
|
174
|
+
provider: 'openrouter',
|
|
175
|
+
model: 'qwen/qwen3.5-flash-02-23',
|
|
176
|
+
apiKey: process.env.OPENROUTER_API_KEY,
|
|
177
|
+
contextLength: 1_000_000,
|
|
178
|
+
maxTokens: 65536,
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### `llm.provider`
|
|
183
|
+
|
|
184
|
+
The API provider. Default: `'openrouter'`.
|
|
185
|
+
|
|
186
|
+
| Provider | Base URL | API Key Env Var |
|
|
187
|
+
| --- | --- | --- |
|
|
188
|
+
| `'openrouter'` | `https://openrouter.ai/api/v1` | `OPENROUTER_API_KEY` |
|
|
189
|
+
| `'openai'` | `https://api.deepseek.com` | `OPENAI_API_KEY` |
|
|
190
|
+
| `'anthropic'` | `https://api.anthropic.com/v1` | `ANTHROPIC_API_KEY` |
|
|
191
|
+
|
|
192
|
+
All providers use the OpenAI-compatible chat completions API.
|
|
193
|
+
|
|
194
|
+
#### `llm.model`
|
|
195
|
+
|
|
196
|
+
The model identifier. Defaults vary by provider:
|
|
197
|
+
|
|
198
|
+
- `openrouter`: `'deepseek/deepseek-chat-v3-0324:free'`
|
|
199
|
+
- `openai`: `'deepseek-chat'`
|
|
200
|
+
- `anthropic`: `'claude-sonnet-4-20250514'`
|
|
201
|
+
|
|
202
|
+
You can also override the model per command with `--model`.
|
|
203
|
+
|
|
204
|
+
#### `llm.apiKey`
|
|
205
|
+
|
|
206
|
+
API key for the provider. Falls back to the corresponding environment variable (`OPENROUTER_API_KEY`, `OPENAI_API_KEY`, or `ANTHROPIC_API_KEY`). Can also be overridden per command with `--api-key`.
|
|
207
|
+
|
|
208
|
+
#### `llm.contextLength`
|
|
209
|
+
|
|
210
|
+
Total context window of the model in tokens. Default: `32768`. Used to calculate how many translation nodes fit in a single API call. Set this to match your model's actual context window for optimal chunking.
|
|
211
|
+
|
|
212
|
+
#### `llm.maxTokens`
|
|
213
|
+
|
|
214
|
+
Maximum output tokens per API call. Default: `16384`. The actual output budget is calculated as `min(maxTokens, contextLength - 4096)`. The translator detects truncated output (when `finish_reason` is `'length'`) and retries.
|
|
215
|
+
|
|
216
|
+
### `onTranslated`
|
|
217
|
+
|
|
218
|
+
**Optional.** Async callback invoked after translation completes for a project/version/language combination.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
onTranslated: async ({ project, version, lang }) => {
|
|
222
|
+
console.log(`Finished translating ${project}/${version} to ${lang}`);
|
|
223
|
+
// Trigger a build, send a notification, etc.
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Example Configurations
|
|
228
|
+
|
|
229
|
+
### Simple single-project setup
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
import { defineConfig } from 'docs-i18n';
|
|
233
|
+
|
|
234
|
+
export default defineConfig({
|
|
235
|
+
projects: {
|
|
236
|
+
docs: {
|
|
237
|
+
sources: { latest: 'docs' },
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
languages: ['zh-hans'],
|
|
241
|
+
llm: {
|
|
242
|
+
provider: 'openrouter',
|
|
243
|
+
apiKey: process.env.OPENROUTER_API_KEY,
|
|
244
|
+
model: 'deepseek/deepseek-chat-v3-0324:free',
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Multi-project monorepo (e.g., TanStack)
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
import { defineConfig } from 'docs-i18n';
|
|
253
|
+
|
|
254
|
+
export default defineConfig({
|
|
255
|
+
projects: {
|
|
256
|
+
query: {
|
|
257
|
+
sources: {
|
|
258
|
+
latest: 'content/query/latest',
|
|
259
|
+
v4: 'content/query/v4',
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
table: {
|
|
263
|
+
sources: { latest: 'content/table/latest' },
|
|
264
|
+
},
|
|
265
|
+
router: {
|
|
266
|
+
sources: { latest: 'content/router/latest' },
|
|
267
|
+
},
|
|
268
|
+
blog: {
|
|
269
|
+
sources: { latest: 'content/blog' },
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
languages: ['zh-hans', 'ja', 'ko', 'es'],
|
|
273
|
+
cacheDir: '.cache',
|
|
274
|
+
translatableFields: ['title', 'description', 'nav_title'],
|
|
275
|
+
include: ['**/*.md'],
|
|
276
|
+
context: 'TanStack provides high-quality open-source libraries for web development including Query, Router, Table, and Form.',
|
|
277
|
+
llm: {
|
|
278
|
+
provider: 'openrouter',
|
|
279
|
+
model: 'qwen/qwen3.5-flash-02-23',
|
|
280
|
+
apiKey: process.env.OPENROUTER_API_KEY,
|
|
281
|
+
contextLength: 1_000_000,
|
|
282
|
+
maxTokens: 65536,
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### Using Anthropic
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
import { defineConfig } from 'docs-i18n';
|
|
291
|
+
|
|
292
|
+
export default defineConfig({
|
|
293
|
+
projects: {
|
|
294
|
+
docs: {
|
|
295
|
+
sources: { latest: 'content/docs' },
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
languages: ['ja', 'fr'],
|
|
299
|
+
llm: {
|
|
300
|
+
provider: 'anthropic',
|
|
301
|
+
model: 'claude-sonnet-4-20250514',
|
|
302
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
303
|
+
contextLength: 200000,
|
|
304
|
+
maxTokens: 16384,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### With post-translation hook
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import { defineConfig } from 'docs-i18n';
|
|
313
|
+
import { exec } from 'node:child_process';
|
|
314
|
+
|
|
315
|
+
export default defineConfig({
|
|
316
|
+
projects: {
|
|
317
|
+
docs: {
|
|
318
|
+
sources: { latest: 'content/docs' },
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
languages: ['zh-hans'],
|
|
322
|
+
llm: {
|
|
323
|
+
provider: 'openrouter',
|
|
324
|
+
apiKey: process.env.OPENROUTER_API_KEY,
|
|
325
|
+
},
|
|
326
|
+
onTranslated: async ({ project, version, lang }) => {
|
|
327
|
+
// Rebuild the site after translation
|
|
328
|
+
exec('npm run build');
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
```
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Deployment
|
|
3
|
+
description: Using docs-i18n in CI/CD pipelines, deploying the admin dashboard, and runtime translation with Cloudflare D1.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Deployment
|
|
7
|
+
|
|
8
|
+
## CI/CD with GitHub Actions
|
|
9
|
+
|
|
10
|
+
docs-i18n works well in CI/CD pipelines. Since translations are cached in SQLite, you only pay for API calls on new or changed content.
|
|
11
|
+
|
|
12
|
+
### Basic translation workflow
|
|
13
|
+
|
|
14
|
+
```yaml
|
|
15
|
+
name: Translate Docs
|
|
16
|
+
on:
|
|
17
|
+
push:
|
|
18
|
+
branches: [main]
|
|
19
|
+
paths:
|
|
20
|
+
- 'content/**'
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
translate:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v4
|
|
27
|
+
|
|
28
|
+
- uses: actions/setup-node@v4
|
|
29
|
+
with:
|
|
30
|
+
node-version: 20
|
|
31
|
+
|
|
32
|
+
- run: npm ci
|
|
33
|
+
|
|
34
|
+
# Restore the SQLite cache from a previous run
|
|
35
|
+
- uses: actions/cache@v4
|
|
36
|
+
with:
|
|
37
|
+
path: .cache
|
|
38
|
+
key: i18n-cache-${{ hashFiles('content/**') }}
|
|
39
|
+
restore-keys: |
|
|
40
|
+
i18n-cache-
|
|
41
|
+
|
|
42
|
+
# Rescan source files to detect changes
|
|
43
|
+
- run: npx docs-i18n rescan
|
|
44
|
+
|
|
45
|
+
# Translate all configured languages
|
|
46
|
+
- run: npx docs-i18n translate --lang zh-hans
|
|
47
|
+
env:
|
|
48
|
+
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
|
49
|
+
|
|
50
|
+
- run: npx docs-i18n translate --lang ja
|
|
51
|
+
env:
|
|
52
|
+
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
|
53
|
+
|
|
54
|
+
# Assemble output files
|
|
55
|
+
- run: npx docs-i18n assemble
|
|
56
|
+
|
|
57
|
+
# Commit translated files (or use them in a build step)
|
|
58
|
+
- uses: stefanzweifel/git-auto-commit-action@v5
|
|
59
|
+
with:
|
|
60
|
+
commit_message: 'chore: update translations'
|
|
61
|
+
file_pattern: '.cache/content/**'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Tips for CI/CD
|
|
65
|
+
|
|
66
|
+
- **Cache the SQLite database.** The `.cache/translations.db` file contains all cached translations. Restoring it between runs avoids re-translating unchanged content. Use `actions/cache` with a key based on your content files.
|
|
67
|
+
- **Run `rescan` before `translate`.** This detects new, changed, and deleted source files, and cleans up orphaned translations.
|
|
68
|
+
- **Use `--dry-run` in PR checks.** Add a CI step that runs `docs-i18n translate --lang zh-hans --dry-run` to report how many nodes need translation without spending API credits.
|
|
69
|
+
- **Limit concurrency.** In CI, you may want `--concurrency 1` to avoid rate limiting from your LLM provider.
|
|
70
|
+
- **Set `--max` for budgeting.** Use `--max 10` to cap the number of API calls per run if you want to translate incrementally across multiple CI runs.
|
|
71
|
+
|
|
72
|
+
### PR status check
|
|
73
|
+
|
|
74
|
+
```yaml
|
|
75
|
+
name: Translation Status
|
|
76
|
+
on:
|
|
77
|
+
pull_request:
|
|
78
|
+
paths:
|
|
79
|
+
- 'content/**'
|
|
80
|
+
|
|
81
|
+
jobs:
|
|
82
|
+
check:
|
|
83
|
+
runs-on: ubuntu-latest
|
|
84
|
+
steps:
|
|
85
|
+
- uses: actions/checkout@v4
|
|
86
|
+
- uses: actions/setup-node@v4
|
|
87
|
+
with:
|
|
88
|
+
node-version: 20
|
|
89
|
+
- run: npm ci
|
|
90
|
+
|
|
91
|
+
- uses: actions/cache@v4
|
|
92
|
+
with:
|
|
93
|
+
path: .cache
|
|
94
|
+
key: i18n-cache-${{ hashFiles('content/**') }}
|
|
95
|
+
restore-keys: |
|
|
96
|
+
i18n-cache-
|
|
97
|
+
|
|
98
|
+
- run: npx docs-i18n rescan
|
|
99
|
+
- run: npx docs-i18n status
|
|
100
|
+
- run: npx docs-i18n translate --lang zh-hans --dry-run
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Admin Dashboard Deployment
|
|
104
|
+
|
|
105
|
+
The admin dashboard is a TanStack Start application that runs locally. It is designed for development use, not production deployment.
|
|
106
|
+
|
|
107
|
+
To start it:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npx docs-i18n admin
|
|
111
|
+
# or
|
|
112
|
+
npx docs-i18n admin --port 4000
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The dashboard starts a Vite dev server pointed at the `src/admin` directory within the docs-i18n package. It reads your `docs-i18n.config.ts` to discover projects, versions, and languages.
|
|
116
|
+
|
|
117
|
+
**Prerequisites:**
|
|
118
|
+
|
|
119
|
+
Your project must have `vite` and `@vitejs/plugin-react` installed as dev dependencies:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npm install -D vite @vitejs/plugin-react
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Runtime Translation with D1
|
|
126
|
+
|
|
127
|
+
For SSR sites that fetch markdown at runtime (e.g., TanStack Start on Cloudflare Workers), docs-i18n provides a lightweight runtime translator that queries Cloudflare D1 for cached translations.
|
|
128
|
+
|
|
129
|
+
### How it works
|
|
130
|
+
|
|
131
|
+
The `createTranslator` function from `docs-i18n/serve` creates a translator instance. When `translate()` is called:
|
|
132
|
+
|
|
133
|
+
1. The markdown is parsed into AST nodes using the same parser as the CLI.
|
|
134
|
+
2. Translatable nodes' MD5 keys are collected.
|
|
135
|
+
3. A batch query is sent to D1 to look up all translations for the given language.
|
|
136
|
+
4. The content is reassembled: translated nodes use the D1 cache value, untranslated nodes fall back to the original English text.
|
|
137
|
+
|
|
138
|
+
### Setup
|
|
139
|
+
|
|
140
|
+
#### 1. Export translations to D1
|
|
141
|
+
|
|
142
|
+
First, translate your content using the CLI as normal. Then export the SQLite cache to D1. You can use Wrangler to create a D1 database and import the translations:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Create a D1 database
|
|
146
|
+
wrangler d1 create docs-translations
|
|
147
|
+
|
|
148
|
+
# Export the translations table from your local SQLite
|
|
149
|
+
sqlite3 .cache/translations.db ".dump translations" > translations.sql
|
|
150
|
+
|
|
151
|
+
# Import into D1
|
|
152
|
+
wrangler d1 execute docs-translations --file=translations.sql
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Make sure the D1 database has the same `translations` table schema:
|
|
156
|
+
|
|
157
|
+
```sql
|
|
158
|
+
CREATE TABLE IF NOT EXISTS translations (
|
|
159
|
+
lang TEXT NOT NULL,
|
|
160
|
+
key TEXT NOT NULL,
|
|
161
|
+
value TEXT NOT NULL,
|
|
162
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
163
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
|
164
|
+
PRIMARY KEY (lang, key)
|
|
165
|
+
);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### 2. Use the translator in your Worker
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { createTranslator } from 'docs-i18n/serve';
|
|
172
|
+
|
|
173
|
+
const translator = createTranslator();
|
|
174
|
+
|
|
175
|
+
// In your request handler (e.g., TanStack Start server function):
|
|
176
|
+
export async function getTranslatedDoc(
|
|
177
|
+
repo: string,
|
|
178
|
+
branch: string,
|
|
179
|
+
filePath: string,
|
|
180
|
+
lang: string,
|
|
181
|
+
env: { DB: D1Database },
|
|
182
|
+
) {
|
|
183
|
+
// Fetch the English markdown from GitHub
|
|
184
|
+
const enMarkdown = await fetchFromGitHub(repo, branch, filePath);
|
|
185
|
+
|
|
186
|
+
// If the requested language is English, return as-is
|
|
187
|
+
if (lang === 'en') return enMarkdown;
|
|
188
|
+
|
|
189
|
+
// Translate using D1 cache
|
|
190
|
+
const translated = await translator.translate(enMarkdown, lang, env.DB);
|
|
191
|
+
return translated;
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### 3. Bind D1 in wrangler.toml
|
|
196
|
+
|
|
197
|
+
```toml
|
|
198
|
+
[[d1_databases]]
|
|
199
|
+
binding = "DB"
|
|
200
|
+
database_name = "docs-translations"
|
|
201
|
+
database_id = "your-database-id"
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Performance considerations
|
|
205
|
+
|
|
206
|
+
- The translator uses a single batch query to D1, so latency scales with the number of translatable nodes (typically under 50ms for a standard documentation page).
|
|
207
|
+
- English content (`lang === 'en'`) short-circuits immediately without parsing or querying.
|
|
208
|
+
- The parser runs on every request since the English source is fetched at runtime. For heavy traffic, consider caching the translated output at the edge.
|
|
209
|
+
- Untranslated nodes gracefully fall back to English, so partial translations work without errors.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Getting Started
|
|
3
|
+
description: Install docs-i18n and translate your first documentation file in minutes.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Getting Started
|
|
7
|
+
|
|
8
|
+
## What is docs-i18n?
|
|
9
|
+
|
|
10
|
+
docs-i18n is a universal documentation translation engine. It parses markdown and MDX files into translatable AST nodes, translates them via LLM, caches results in SQLite, and assembles translated output files. It is framework-agnostic and works with any documentation site built on Next.js, Astro, TanStack Start, or similar tools.
|
|
11
|
+
|
|
12
|
+
Key characteristics:
|
|
13
|
+
|
|
14
|
+
- **Incremental** -- only changed or new content is sent to the LLM.
|
|
15
|
+
- **AST-based** -- uses remark to parse markdown into nodes, producing stable MD5 keys for deduplication.
|
|
16
|
+
- **SQLite-backed** -- concurrent-safe cache with WAL mode. No manual save steps.
|
|
17
|
+
- **Multi-project** -- supports multiple documentation projects and versions in a single config.
|
|
18
|
+
- **Admin dashboard** -- web UI for monitoring progress, managing jobs, and previewing translations.
|
|
19
|
+
- **Runtime serve** -- optional D1-compatible translator for SSR sites on Cloudflare Workers.
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Node.js 20+ or Bun
|
|
24
|
+
- An API key for an LLM provider (OpenRouter, OpenAI, or Anthropic)
|
|
25
|
+
- For the admin dashboard: `vite` and `@vitejs/plugin-react` as dev dependencies
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install docs-i18n
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or with Bun:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bun add docs-i18n
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
### 1. Create a configuration file
|
|
42
|
+
|
|
43
|
+
Create `docs-i18n.config.ts` in your project root:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { defineConfig } from 'docs-i18n';
|
|
47
|
+
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
projects: {
|
|
50
|
+
mydocs: {
|
|
51
|
+
sources: {
|
|
52
|
+
latest: 'content/docs',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
languages: ['zh-hans', 'ja', 'es'],
|
|
57
|
+
llm: {
|
|
58
|
+
provider: 'openrouter',
|
|
59
|
+
model: 'deepseek/deepseek-chat-v3-0324:free',
|
|
60
|
+
apiKey: process.env.OPENROUTER_API_KEY,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The `projects` object maps project names to their source directories. Each project can have multiple versions (e.g., `latest`, `v1`, `v2`). The `languages` array lists the target language codes to translate into.
|
|
66
|
+
|
|
67
|
+
### 2. Scan your source files
|
|
68
|
+
|
|
69
|
+
Before translating, scan your English source files to build the source index:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx docs-i18n rescan
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This parses every markdown/MDX file in your source directories, extracts translatable nodes, and stores them in the SQLite cache.
|
|
76
|
+
|
|
77
|
+
### 3. Check translation status
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npx docs-i18n status
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This displays a progress bar for each language showing how many nodes have been translated.
|
|
84
|
+
|
|
85
|
+
### 4. Run your first translation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx docs-i18n translate --lang zh-hans
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This sends untranslated nodes to your configured LLM, receives translations, and stores them in the cache. Only new or changed content is translated -- cached translations are reused.
|
|
92
|
+
|
|
93
|
+
### 5. Assemble output files
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx docs-i18n assemble
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
This produces translated markdown files by combining your English sources with cached translations. Output is written to `.cache/content/<version>/<lang>/` by default.
|
|
100
|
+
|
|
101
|
+
## Minimal Working Example
|
|
102
|
+
|
|
103
|
+
Given this project structure:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
my-docs/
|
|
107
|
+
content/
|
|
108
|
+
docs/
|
|
109
|
+
getting-started.md
|
|
110
|
+
api-reference.md
|
|
111
|
+
docs-i18n.config.ts
|
|
112
|
+
package.json
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
With this config:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { defineConfig } from 'docs-i18n';
|
|
119
|
+
|
|
120
|
+
export default defineConfig({
|
|
121
|
+
projects: {
|
|
122
|
+
docs: {
|
|
123
|
+
sources: { latest: 'content/docs' },
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
languages: ['zh-hans'],
|
|
127
|
+
llm: {
|
|
128
|
+
provider: 'openrouter',
|
|
129
|
+
apiKey: process.env.OPENROUTER_API_KEY,
|
|
130
|
+
model: 'deepseek/deepseek-chat-v3-0324:free',
|
|
131
|
+
contextLength: 32768,
|
|
132
|
+
maxTokens: 16384,
|
|
133
|
+
},
|
|
134
|
+
context: 'MyProject is a TypeScript library for building web apps.',
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Run these commands:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npx docs-i18n rescan
|
|
142
|
+
npx docs-i18n translate --lang zh-hans
|
|
143
|
+
npx docs-i18n assemble --lang zh-hans
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The translated files will appear at:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
.cache/content/latest/zh-hans/getting-started.md
|
|
150
|
+
.cache/content/latest/zh-hans/api-reference.md
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Adding npm scripts
|
|
154
|
+
|
|
155
|
+
Add these convenience scripts to your `package.json`:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"scripts": {
|
|
160
|
+
"i18n": "docs-i18n",
|
|
161
|
+
"i18n:status": "docs-i18n status",
|
|
162
|
+
"i18n:translate": "docs-i18n translate",
|
|
163
|
+
"i18n:assemble": "docs-i18n assemble",
|
|
164
|
+
"i18n:rescan": "docs-i18n rescan",
|
|
165
|
+
"i18n:admin": "docs-i18n admin"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|