@p6t/cli 0.1.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 +136 -0
- package/dist/index.js +1029 -0
- package/dist/lingui-VSOT4HY4.js +222 -0
- package/dist/react-intl-EIVHSW57.js +222 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @p6t/cli
|
|
2
|
+
|
|
3
|
+
LLM-powered translation pipeline CLI for p6t.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
| Command | Description |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `p6t init` | Scaffold `i18n.json` and context files; optionally drafts them with an LLM |
|
|
10
|
+
| `p6t translate` | Translate missing strings in Lingui catalogs using an LLM |
|
|
11
|
+
| `p6t push` | Push translations to p6t web for human review _(coming soon)_ |
|
|
12
|
+
| `p6t pull` | Pull confirmed translations from p6t web _(coming soon)_ |
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# 1. Install
|
|
18
|
+
npm install -g @p6t/cli
|
|
19
|
+
|
|
20
|
+
# 2. Initialise — creates i18n.json and context files
|
|
21
|
+
p6t init
|
|
22
|
+
|
|
23
|
+
# 3. Extract strings (Lingui)
|
|
24
|
+
lingui extract
|
|
25
|
+
|
|
26
|
+
# 4. Translate
|
|
27
|
+
p6t translate
|
|
28
|
+
|
|
29
|
+
# 5. Compile (Lingui)
|
|
30
|
+
lingui compile
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Configuration — `i18n.json`
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"$schema": "https://p6t.dev/schema/i18n.json",
|
|
38
|
+
"version": 1,
|
|
39
|
+
"locale": {
|
|
40
|
+
"source": "en",
|
|
41
|
+
"targets": ["de", "fr", "es"]
|
|
42
|
+
},
|
|
43
|
+
"provider": {
|
|
44
|
+
"id": "openai",
|
|
45
|
+
"model": "gpt-4o"
|
|
46
|
+
},
|
|
47
|
+
"context": {
|
|
48
|
+
"description": "i18n/description.md",
|
|
49
|
+
"styleGuide": "i18n/{locale}/style-guide.md",
|
|
50
|
+
"glossary": "i18n/{locale}/glossary.json"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### `locale`
|
|
56
|
+
|
|
57
|
+
| Field | Description |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `source` | Locale your source strings are written in |
|
|
60
|
+
| `targets` | Locales to translate into |
|
|
61
|
+
|
|
62
|
+
### `provider`
|
|
63
|
+
|
|
64
|
+
| Field | Description |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `id` | `openai` \| `anthropic` \| `google` \| `mistral` \| `ollama` \| `openrouter` |
|
|
67
|
+
| `model` | Model name (e.g. `gpt-4o`, `claude-sonnet-4-5`) |
|
|
68
|
+
| `prompt` | Optional system prompt override |
|
|
69
|
+
| `baseUrl` | Optional API base URL override |
|
|
70
|
+
|
|
71
|
+
### `context`
|
|
72
|
+
|
|
73
|
+
Paths to the translation context files (all optional — omitting a file means that context is skipped).
|
|
74
|
+
`{locale}` in a path is replaced with the target locale at runtime.
|
|
75
|
+
|
|
76
|
+
### `projectId` _(optional)_
|
|
77
|
+
|
|
78
|
+
Ties this project to a p6t web project. Required for `push` and `pull` once web integration ships.
|
|
79
|
+
|
|
80
|
+
## Environment variables
|
|
81
|
+
|
|
82
|
+
| Variable | Provider |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `OPENAI_API_KEY` | OpenAI |
|
|
85
|
+
| `ANTHROPIC_API_KEY` | Anthropic |
|
|
86
|
+
| `GOOGLE_AI_API_KEY` or `GEMINI_API_KEY` | Google |
|
|
87
|
+
| `MISTRAL_API_KEY` | Mistral |
|
|
88
|
+
| `OPENROUTER_API_KEY` | OpenRouter |
|
|
89
|
+
| `P6T_API_KEY` | p6t web (push/pull) |
|
|
90
|
+
|
|
91
|
+
Ollama requires no API key — set `provider.baseUrl` if your Ollama server is not on `localhost:11434`.
|
|
92
|
+
|
|
93
|
+
## Context files
|
|
94
|
+
|
|
95
|
+
`p6t init` creates these files. Commit them. They are sent as context on every LLM translation call.
|
|
96
|
+
|
|
97
|
+
### `i18n/description.md`
|
|
98
|
+
|
|
99
|
+
Plain English description of your project for translators: what it does, who uses it, industry/domain, vocabulary notes. One file shared across all locales.
|
|
100
|
+
|
|
101
|
+
### `i18n/{locale}/style-guide.md`
|
|
102
|
+
|
|
103
|
+
Per-locale rules for tone, formality (formal/informal), brand voice, punctuation, and number/date formatting.
|
|
104
|
+
|
|
105
|
+
### `i18n/{locale}/glossary.json`
|
|
106
|
+
|
|
107
|
+
Flat JSON mapping source terms to their required target translations:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"checkout": "Kasse",
|
|
112
|
+
"dashboard": "Dashboard"
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The CLI instructs the LLM to use these exact translations whenever the terms appear.
|
|
117
|
+
|
|
118
|
+
## Lingui catalog discovery
|
|
119
|
+
|
|
120
|
+
The CLI reads your `lingui.config.*` (or `package.json` `"lingui"` key) via `@lingui/conf` to find catalog paths. No duplication needed in `i18n.json`.
|
|
121
|
+
|
|
122
|
+
## Translation behaviour
|
|
123
|
+
|
|
124
|
+
- **Incremental:** only strings with an empty or fuzzy `msgstr` are sent to the LLM. Existing translations are never overwritten.
|
|
125
|
+
- **Batched:** strings are sent in batches of 200 (configurable internally). The LLM receives all context on every batch.
|
|
126
|
+
- **Format:** strings are serialised in a compact `---`-delimited format. The LLM is instructed to maintain ICU message syntax and produce the correct plural categories for each target locale.
|
|
127
|
+
|
|
128
|
+
## Build
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pnpm build # tsup → dist/index.js (ESM, shebang included)
|
|
132
|
+
pnpm build:dev # tsup --watch
|
|
133
|
+
pnpm typecheck # tsc --noEmit
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Requires Node 22+. No other runtime needed.
|