@llm-translate/cli 1.0.0-next.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/.dockerignore +51 -0
- package/.env.example +33 -0
- package/.github/workflows/docs-pages.yml +57 -0
- package/.github/workflows/release.yml +49 -0
- package/.translaterc.json +44 -0
- package/CLAUDE.md +243 -0
- package/Dockerfile +55 -0
- package/README.md +371 -0
- package/RFC.md +1595 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +4494 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +1152 -0
- package/dist/index.js +3841 -0
- package/dist/index.js.map +1 -0
- package/docker-compose.yml +56 -0
- package/docs/.vitepress/config.ts +161 -0
- package/docs/api/agent.md +262 -0
- package/docs/api/engine.md +274 -0
- package/docs/api/index.md +171 -0
- package/docs/api/providers.md +304 -0
- package/docs/changelog.md +64 -0
- package/docs/cli/dir.md +243 -0
- package/docs/cli/file.md +213 -0
- package/docs/cli/glossary.md +273 -0
- package/docs/cli/index.md +129 -0
- package/docs/cli/init.md +158 -0
- package/docs/cli/serve.md +211 -0
- package/docs/glossary.json +235 -0
- package/docs/guide/chunking.md +272 -0
- package/docs/guide/configuration.md +139 -0
- package/docs/guide/cost-optimization.md +237 -0
- package/docs/guide/docker.md +371 -0
- package/docs/guide/getting-started.md +150 -0
- package/docs/guide/glossary.md +241 -0
- package/docs/guide/index.md +86 -0
- package/docs/guide/ollama.md +515 -0
- package/docs/guide/prompt-caching.md +221 -0
- package/docs/guide/providers.md +232 -0
- package/docs/guide/quality-control.md +206 -0
- package/docs/guide/vitepress-integration.md +265 -0
- package/docs/index.md +63 -0
- package/docs/ja/api/agent.md +262 -0
- package/docs/ja/api/engine.md +274 -0
- package/docs/ja/api/index.md +171 -0
- package/docs/ja/api/providers.md +304 -0
- package/docs/ja/changelog.md +64 -0
- package/docs/ja/cli/dir.md +243 -0
- package/docs/ja/cli/file.md +213 -0
- package/docs/ja/cli/glossary.md +273 -0
- package/docs/ja/cli/index.md +111 -0
- package/docs/ja/cli/init.md +158 -0
- package/docs/ja/guide/chunking.md +271 -0
- package/docs/ja/guide/configuration.md +139 -0
- package/docs/ja/guide/cost-optimization.md +30 -0
- package/docs/ja/guide/getting-started.md +150 -0
- package/docs/ja/guide/glossary.md +214 -0
- package/docs/ja/guide/index.md +32 -0
- package/docs/ja/guide/ollama.md +410 -0
- package/docs/ja/guide/prompt-caching.md +221 -0
- package/docs/ja/guide/providers.md +232 -0
- package/docs/ja/guide/quality-control.md +137 -0
- package/docs/ja/guide/vitepress-integration.md +265 -0
- package/docs/ja/index.md +58 -0
- package/docs/ko/api/agent.md +262 -0
- package/docs/ko/api/engine.md +274 -0
- package/docs/ko/api/index.md +171 -0
- package/docs/ko/api/providers.md +304 -0
- package/docs/ko/changelog.md +64 -0
- package/docs/ko/cli/dir.md +243 -0
- package/docs/ko/cli/file.md +213 -0
- package/docs/ko/cli/glossary.md +273 -0
- package/docs/ko/cli/index.md +111 -0
- package/docs/ko/cli/init.md +158 -0
- package/docs/ko/guide/chunking.md +271 -0
- package/docs/ko/guide/configuration.md +139 -0
- package/docs/ko/guide/cost-optimization.md +30 -0
- package/docs/ko/guide/getting-started.md +150 -0
- package/docs/ko/guide/glossary.md +214 -0
- package/docs/ko/guide/index.md +32 -0
- package/docs/ko/guide/ollama.md +410 -0
- package/docs/ko/guide/prompt-caching.md +221 -0
- package/docs/ko/guide/providers.md +232 -0
- package/docs/ko/guide/quality-control.md +137 -0
- package/docs/ko/guide/vitepress-integration.md +265 -0
- package/docs/ko/index.md +58 -0
- package/docs/zh/api/agent.md +262 -0
- package/docs/zh/api/engine.md +274 -0
- package/docs/zh/api/index.md +171 -0
- package/docs/zh/api/providers.md +304 -0
- package/docs/zh/changelog.md +64 -0
- package/docs/zh/cli/dir.md +243 -0
- package/docs/zh/cli/file.md +213 -0
- package/docs/zh/cli/glossary.md +273 -0
- package/docs/zh/cli/index.md +111 -0
- package/docs/zh/cli/init.md +158 -0
- package/docs/zh/guide/chunking.md +271 -0
- package/docs/zh/guide/configuration.md +139 -0
- package/docs/zh/guide/cost-optimization.md +30 -0
- package/docs/zh/guide/getting-started.md +150 -0
- package/docs/zh/guide/glossary.md +214 -0
- package/docs/zh/guide/index.md +32 -0
- package/docs/zh/guide/ollama.md +410 -0
- package/docs/zh/guide/prompt-caching.md +221 -0
- package/docs/zh/guide/providers.md +232 -0
- package/docs/zh/guide/quality-control.md +137 -0
- package/docs/zh/guide/vitepress-integration.md +265 -0
- package/docs/zh/index.md +58 -0
- package/package.json +91 -0
- package/release.config.mjs +15 -0
- package/schemas/glossary.schema.json +110 -0
- package/src/cli/commands/dir.ts +469 -0
- package/src/cli/commands/file.ts +291 -0
- package/src/cli/commands/glossary.ts +221 -0
- package/src/cli/commands/init.ts +68 -0
- package/src/cli/commands/serve.ts +60 -0
- package/src/cli/index.ts +64 -0
- package/src/cli/options.ts +59 -0
- package/src/core/agent.ts +1119 -0
- package/src/core/chunker.ts +391 -0
- package/src/core/engine.ts +634 -0
- package/src/errors.ts +188 -0
- package/src/index.ts +147 -0
- package/src/integrations/vitepress.ts +549 -0
- package/src/parsers/markdown.ts +383 -0
- package/src/providers/claude.ts +259 -0
- package/src/providers/interface.ts +109 -0
- package/src/providers/ollama.ts +379 -0
- package/src/providers/openai.ts +308 -0
- package/src/providers/registry.ts +153 -0
- package/src/server/index.ts +152 -0
- package/src/server/middleware/auth.ts +93 -0
- package/src/server/middleware/logger.ts +90 -0
- package/src/server/routes/health.ts +84 -0
- package/src/server/routes/translate.ts +210 -0
- package/src/server/types.ts +138 -0
- package/src/services/cache.ts +899 -0
- package/src/services/config.ts +217 -0
- package/src/services/glossary.ts +247 -0
- package/src/types/analysis.ts +164 -0
- package/src/types/index.ts +265 -0
- package/src/types/modes.ts +121 -0
- package/src/types/mqm.ts +157 -0
- package/src/utils/logger.ts +141 -0
- package/src/utils/tokens.ts +116 -0
- package/tests/fixtures/glossaries/ml-glossary.json +53 -0
- package/tests/fixtures/input/lynq-installation.ko.md +350 -0
- package/tests/fixtures/input/lynq-installation.md +350 -0
- package/tests/fixtures/input/simple.ko.md +27 -0
- package/tests/fixtures/input/simple.md +27 -0
- package/tests/unit/chunker.test.ts +229 -0
- package/tests/unit/glossary.test.ts +146 -0
- package/tests/unit/markdown.test.ts +205 -0
- package/tests/unit/tokens.test.ts +81 -0
- package/tsconfig.json +28 -0
- package/tsup.config.ts +34 -0
- package/vitest.config.ts +16 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
# Docker Deployment
|
|
2
|
+
|
|
3
|
+
Deploy llm-translate as a containerized API service.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Clone the repository
|
|
9
|
+
git clone https://github.com/your-org/llm-translate.git
|
|
10
|
+
cd llm-translate
|
|
11
|
+
|
|
12
|
+
# Copy environment template
|
|
13
|
+
cp .env.example .env
|
|
14
|
+
|
|
15
|
+
# Edit .env with your API keys
|
|
16
|
+
nano .env
|
|
17
|
+
|
|
18
|
+
# Build and start
|
|
19
|
+
docker compose up -d
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Building the Image
|
|
23
|
+
|
|
24
|
+
### Using Docker
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Build production image
|
|
28
|
+
docker build -t llm-translate .
|
|
29
|
+
|
|
30
|
+
# Build with specific tag
|
|
31
|
+
docker build -t llm-translate:v1.0.0 .
|
|
32
|
+
|
|
33
|
+
# Build without cache
|
|
34
|
+
docker build --no-cache -t llm-translate .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Image Details
|
|
38
|
+
|
|
39
|
+
The Dockerfile uses a multi-stage build:
|
|
40
|
+
|
|
41
|
+
1. **Builder stage**: Installs dependencies and compiles TypeScript
|
|
42
|
+
2. **Production stage**: Copies only production artifacts
|
|
43
|
+
|
|
44
|
+
Features:
|
|
45
|
+
- Based on `node:24-alpine` for minimal size
|
|
46
|
+
- Runs as non-root user (`llmtranslate`)
|
|
47
|
+
- Built-in health check
|
|
48
|
+
- JSON logging for container environments
|
|
49
|
+
|
|
50
|
+
## Running with Docker
|
|
51
|
+
|
|
52
|
+
### Basic Usage
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
docker run -d \
|
|
56
|
+
--name llm-translate-api \
|
|
57
|
+
-p 3000:3000 \
|
|
58
|
+
-e ANTHROPIC_API_KEY=sk-ant-xxxxx \
|
|
59
|
+
-e TRANSLATE_API_KEY=your-api-key \
|
|
60
|
+
llm-translate
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### With All Options
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
docker run -d \
|
|
67
|
+
--name llm-translate-api \
|
|
68
|
+
-p 3000:3000 \
|
|
69
|
+
-e TRANSLATE_PORT=3000 \
|
|
70
|
+
-e TRANSLATE_API_KEY=your-secure-api-key \
|
|
71
|
+
-e ANTHROPIC_API_KEY=sk-ant-xxxxx \
|
|
72
|
+
-e OPENAI_API_KEY=sk-xxxxx \
|
|
73
|
+
--restart unless-stopped \
|
|
74
|
+
--memory 512m \
|
|
75
|
+
--cpus 1 \
|
|
76
|
+
llm-translate
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Check Container Health
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# View container status
|
|
83
|
+
docker ps
|
|
84
|
+
|
|
85
|
+
# Check health status
|
|
86
|
+
docker inspect llm-translate-api --format='{{.State.Health.Status}}'
|
|
87
|
+
|
|
88
|
+
# View logs
|
|
89
|
+
docker logs -f llm-translate-api
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Running with Docker Compose
|
|
93
|
+
|
|
94
|
+
### Default Configuration
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Start service
|
|
98
|
+
docker compose up -d
|
|
99
|
+
|
|
100
|
+
# View logs
|
|
101
|
+
docker compose logs -f
|
|
102
|
+
|
|
103
|
+
# Stop service
|
|
104
|
+
docker compose down
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### With Local Ollama
|
|
108
|
+
|
|
109
|
+
Run with the `with-ollama` profile to include a local Ollama instance:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
docker compose --profile with-ollama up -d
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### docker-compose.yml
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
version: '3.8'
|
|
119
|
+
|
|
120
|
+
services:
|
|
121
|
+
llm-translate:
|
|
122
|
+
build: .
|
|
123
|
+
container_name: llm-translate-api
|
|
124
|
+
restart: unless-stopped
|
|
125
|
+
ports:
|
|
126
|
+
- "${TRANSLATE_PORT:-3000}:3000"
|
|
127
|
+
environment:
|
|
128
|
+
- NODE_ENV=production
|
|
129
|
+
- TRANSLATE_API_KEY=${TRANSLATE_API_KEY}
|
|
130
|
+
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
|
|
131
|
+
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
|
132
|
+
- OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://ollama:11434}
|
|
133
|
+
healthcheck:
|
|
134
|
+
test: ["CMD", "node", "-e", "fetch('http://localhost:3000/health/live').then(r => r.ok ? process.exit(0) : process.exit(1))"]
|
|
135
|
+
interval: 30s
|
|
136
|
+
timeout: 5s
|
|
137
|
+
retries: 3
|
|
138
|
+
start_period: 10s
|
|
139
|
+
deploy:
|
|
140
|
+
resources:
|
|
141
|
+
limits:
|
|
142
|
+
memory: 512M
|
|
143
|
+
reservations:
|
|
144
|
+
memory: 256M
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Kubernetes Deployment
|
|
148
|
+
|
|
149
|
+
### Deployment Manifest
|
|
150
|
+
|
|
151
|
+
```yaml
|
|
152
|
+
apiVersion: apps/v1
|
|
153
|
+
kind: Deployment
|
|
154
|
+
metadata:
|
|
155
|
+
name: llm-translate
|
|
156
|
+
labels:
|
|
157
|
+
app: llm-translate
|
|
158
|
+
spec:
|
|
159
|
+
replicas: 2
|
|
160
|
+
selector:
|
|
161
|
+
matchLabels:
|
|
162
|
+
app: llm-translate
|
|
163
|
+
template:
|
|
164
|
+
metadata:
|
|
165
|
+
labels:
|
|
166
|
+
app: llm-translate
|
|
167
|
+
spec:
|
|
168
|
+
containers:
|
|
169
|
+
- name: llm-translate
|
|
170
|
+
image: llm-translate:latest
|
|
171
|
+
ports:
|
|
172
|
+
- containerPort: 3000
|
|
173
|
+
env:
|
|
174
|
+
- name: TRANSLATE_API_KEY
|
|
175
|
+
valueFrom:
|
|
176
|
+
secretKeyRef:
|
|
177
|
+
name: llm-translate-secrets
|
|
178
|
+
key: api-key
|
|
179
|
+
- name: ANTHROPIC_API_KEY
|
|
180
|
+
valueFrom:
|
|
181
|
+
secretKeyRef:
|
|
182
|
+
name: llm-translate-secrets
|
|
183
|
+
key: anthropic-key
|
|
184
|
+
resources:
|
|
185
|
+
limits:
|
|
186
|
+
memory: "512Mi"
|
|
187
|
+
cpu: "1000m"
|
|
188
|
+
requests:
|
|
189
|
+
memory: "256Mi"
|
|
190
|
+
cpu: "250m"
|
|
191
|
+
livenessProbe:
|
|
192
|
+
httpGet:
|
|
193
|
+
path: /health/live
|
|
194
|
+
port: 3000
|
|
195
|
+
initialDelaySeconds: 10
|
|
196
|
+
periodSeconds: 10
|
|
197
|
+
readinessProbe:
|
|
198
|
+
httpGet:
|
|
199
|
+
path: /health/ready
|
|
200
|
+
port: 3000
|
|
201
|
+
initialDelaySeconds: 5
|
|
202
|
+
periodSeconds: 10
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Service Manifest
|
|
206
|
+
|
|
207
|
+
```yaml
|
|
208
|
+
apiVersion: v1
|
|
209
|
+
kind: Service
|
|
210
|
+
metadata:
|
|
211
|
+
name: llm-translate
|
|
212
|
+
spec:
|
|
213
|
+
selector:
|
|
214
|
+
app: llm-translate
|
|
215
|
+
ports:
|
|
216
|
+
- protocol: TCP
|
|
217
|
+
port: 80
|
|
218
|
+
targetPort: 3000
|
|
219
|
+
type: ClusterIP
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Secret Manifest
|
|
223
|
+
|
|
224
|
+
```yaml
|
|
225
|
+
apiVersion: v1
|
|
226
|
+
kind: Secret
|
|
227
|
+
metadata:
|
|
228
|
+
name: llm-translate-secrets
|
|
229
|
+
type: Opaque
|
|
230
|
+
stringData:
|
|
231
|
+
api-key: "your-translate-api-key"
|
|
232
|
+
anthropic-key: "sk-ant-xxxxx"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Configuration
|
|
236
|
+
|
|
237
|
+
### Environment Variables
|
|
238
|
+
|
|
239
|
+
| Variable | Required | Description |
|
|
240
|
+
|----------|----------|-------------|
|
|
241
|
+
| `TRANSLATE_PORT` | No | Server port (default: 3000) |
|
|
242
|
+
| `TRANSLATE_API_KEY` | Recommended | API authentication key |
|
|
243
|
+
| `ANTHROPIC_API_KEY` | One required | Claude API key |
|
|
244
|
+
| `OPENAI_API_KEY` | One required | OpenAI API key |
|
|
245
|
+
| `OLLAMA_BASE_URL` | No | Ollama server URL |
|
|
246
|
+
|
|
247
|
+
### Resource Recommendations
|
|
248
|
+
|
|
249
|
+
| Environment | Memory | CPU |
|
|
250
|
+
|-------------|--------|-----|
|
|
251
|
+
| Development | 256MB | 0.5 |
|
|
252
|
+
| Production | 512MB | 1.0 |
|
|
253
|
+
| High load | 1GB | 2.0 |
|
|
254
|
+
|
|
255
|
+
## Health Checks
|
|
256
|
+
|
|
257
|
+
The container includes built-in health checks:
|
|
258
|
+
|
|
259
|
+
| Endpoint | Purpose | Response |
|
|
260
|
+
|----------|---------|----------|
|
|
261
|
+
| `/health` | Full status | JSON with provider info |
|
|
262
|
+
| `/health/live` | Liveness | `{"status": "ok"}` |
|
|
263
|
+
| `/health/ready` | Readiness | `{"status": "ready"}` |
|
|
264
|
+
|
|
265
|
+
### Health Check Configuration
|
|
266
|
+
|
|
267
|
+
```dockerfile
|
|
268
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
269
|
+
CMD node -e "fetch('http://localhost:3000/health/live').then(r => r.ok ? process.exit(0) : process.exit(1))"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## Logging
|
|
273
|
+
|
|
274
|
+
### JSON Logging (Default in Container)
|
|
275
|
+
|
|
276
|
+
The server uses JSON logging by default when running with `--json` flag:
|
|
277
|
+
|
|
278
|
+
```json
|
|
279
|
+
{"timestamp":"2024-01-15T10:30:45.123Z","requestId":"abc123","method":"POST","path":"/translate","status":200,"duration":1234}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Log Aggregation
|
|
283
|
+
|
|
284
|
+
Configure your log aggregator to parse JSON logs:
|
|
285
|
+
|
|
286
|
+
```yaml
|
|
287
|
+
# Fluentd example
|
|
288
|
+
<filter docker.**>
|
|
289
|
+
@type parser
|
|
290
|
+
key_name log
|
|
291
|
+
<parse>
|
|
292
|
+
@type json
|
|
293
|
+
</parse>
|
|
294
|
+
</filter>
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Security Considerations
|
|
298
|
+
|
|
299
|
+
### API Authentication
|
|
300
|
+
|
|
301
|
+
Always set `TRANSLATE_API_KEY` in production:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
# Generate a secure key
|
|
305
|
+
export TRANSLATE_API_KEY=$(openssl rand -base64 32)
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Network Security
|
|
309
|
+
|
|
310
|
+
1. **Internal network**: Run behind a reverse proxy
|
|
311
|
+
2. **TLS termination**: Use nginx/traefik for HTTPS
|
|
312
|
+
3. **Rate limiting**: Configure at proxy level
|
|
313
|
+
|
|
314
|
+
### Example Nginx Configuration
|
|
315
|
+
|
|
316
|
+
```nginx
|
|
317
|
+
upstream llm-translate {
|
|
318
|
+
server localhost:3000;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
server {
|
|
322
|
+
listen 443 ssl http2;
|
|
323
|
+
server_name translate.example.com;
|
|
324
|
+
|
|
325
|
+
ssl_certificate /etc/ssl/cert.pem;
|
|
326
|
+
ssl_certificate_key /etc/ssl/key.pem;
|
|
327
|
+
|
|
328
|
+
location / {
|
|
329
|
+
proxy_pass http://llm-translate;
|
|
330
|
+
proxy_set_header Host $host;
|
|
331
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
332
|
+
|
|
333
|
+
# Rate limiting
|
|
334
|
+
limit_req zone=api burst=10 nodelay;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Troubleshooting
|
|
340
|
+
|
|
341
|
+
### Container won't start
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# Check logs
|
|
345
|
+
docker logs llm-translate-api
|
|
346
|
+
|
|
347
|
+
# Common issues:
|
|
348
|
+
# - Missing API keys
|
|
349
|
+
# - Port already in use
|
|
350
|
+
# - Insufficient memory
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Health check failing
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
# Test health endpoint manually
|
|
357
|
+
curl http://localhost:3000/health
|
|
358
|
+
|
|
359
|
+
# Check if providers are configured
|
|
360
|
+
docker exec llm-translate-api env | grep API_KEY
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### High memory usage
|
|
364
|
+
|
|
365
|
+
```bash
|
|
366
|
+
# Check memory usage
|
|
367
|
+
docker stats llm-translate-api
|
|
368
|
+
|
|
369
|
+
# Increase memory limit if needed
|
|
370
|
+
docker update --memory 1g llm-translate-api
|
|
371
|
+
```
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
::: info Translations
|
|
4
|
+
All non-English documentation is automatically translated using Claude Sonnet 4.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### npm (Recommended)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g @llm-translate/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### From Source
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/selenehyun/llm-translate.git
|
|
19
|
+
cd llm-translate
|
|
20
|
+
npm install
|
|
21
|
+
npm run build
|
|
22
|
+
npm link
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
- Node.js 24 or higher
|
|
28
|
+
- API key for at least one LLM provider:
|
|
29
|
+
- Anthropic (Claude)
|
|
30
|
+
- OpenAI
|
|
31
|
+
- Ollama (local, no API key needed)
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
### 1. Set API Key
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# For Claude (recommended)
|
|
39
|
+
export ANTHROPIC_API_KEY=sk-ant-xxxxx
|
|
40
|
+
|
|
41
|
+
# For OpenAI
|
|
42
|
+
export OPENAI_API_KEY=sk-xxxxx
|
|
43
|
+
|
|
44
|
+
# For Ollama (no key needed, just ensure server is running)
|
|
45
|
+
# See the Ollama guide for setup: ./ollama
|
|
46
|
+
export OLLAMA_BASE_URL=http://localhost:11434
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Initialize Configuration (Optional)
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
llm-translate init
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This creates a `.translaterc.json` file with default settings:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"provider": {
|
|
60
|
+
"name": "claude",
|
|
61
|
+
"model": "claude-haiku-4-5-20251001"
|
|
62
|
+
},
|
|
63
|
+
"translation": {
|
|
64
|
+
"qualityThreshold": 85,
|
|
65
|
+
"maxIterations": 4
|
|
66
|
+
},
|
|
67
|
+
"paths": {
|
|
68
|
+
"glossary": "./glossary.json"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Your First Translation
|
|
74
|
+
|
|
75
|
+
### Basic Usage
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Translate a markdown file to Korean
|
|
79
|
+
llm-translate file README.md -o README.ko.md -s en -t ko
|
|
80
|
+
|
|
81
|
+
# Using long option names
|
|
82
|
+
llm-translate file docs/guide.md -o docs/guide.ja.md --source-lang en --target-lang ja
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Using a Glossary
|
|
86
|
+
|
|
87
|
+
1. Create a `glossary.json` file:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"sourceLanguage": "en",
|
|
92
|
+
"terms": [
|
|
93
|
+
{
|
|
94
|
+
"source": "component",
|
|
95
|
+
"targets": { "ko": "컴포넌트" },
|
|
96
|
+
"context": "UI component"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"source": "prop",
|
|
100
|
+
"targets": { "ko": "프롭" },
|
|
101
|
+
"context": "React prop"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"source": "TypeScript",
|
|
105
|
+
"doNotTranslate": true
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
2. Translate with glossary:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
llm-translate file README.md -o README.ko.md -s en -t ko --glossary glossary.json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Batch Translation
|
|
118
|
+
|
|
119
|
+
Translate an entire directory:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
llm-translate dir ./docs ./docs-ko -s en -t ko --glossary glossary.json
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Understanding the Output
|
|
126
|
+
|
|
127
|
+
After translation, you'll see:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
✓ Translation complete
|
|
131
|
+
Quality: 92/85 (threshold met)
|
|
132
|
+
Iterations: 2
|
|
133
|
+
Tokens: 1,234 input / 1,456 output
|
|
134
|
+
Cache: 890 read / 234 written (78% hit rate)
|
|
135
|
+
Duration: 3.2s
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
- **Quality**: Final score vs threshold
|
|
139
|
+
- **Iterations**: Number of refinement cycles
|
|
140
|
+
- **Tokens**: API token usage
|
|
141
|
+
- **Cache**: Prompt caching statistics (Claude only)
|
|
142
|
+
- **Duration**: Total processing time
|
|
143
|
+
|
|
144
|
+
## Next Steps
|
|
145
|
+
|
|
146
|
+
- [Configure your project](./configuration) for optimal settings
|
|
147
|
+
- [Set up a glossary](./glossary) for consistent terminology
|
|
148
|
+
- [Understand quality control](./quality-control) and tuning
|
|
149
|
+
- [Optimize costs](./cost-optimization) for large projects
|
|
150
|
+
- [Run locally with Ollama](./ollama) for private, offline translation
|