poly-lexis 0.3.2 → 0.4.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 +87 -17
- package/dist/cli/translations.js +527 -125
- package/dist/cli/translations.js.map +1 -1
- package/dist/index.d.ts +189 -113
- package/dist/index.js +531 -123
- package/dist/index.js.map +1 -1
- package/dist/scripts/generate-schema.js +5 -0
- package/dist/scripts/generate-schema.js.map +1 -1
- package/dist/scripts/verify-translations.js +73 -4
- package/dist/scripts/verify-translations.js.map +1 -1
- package/dist/translations/core/translations-config.schema.json +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A powerful CLI and library for managing i18n translations with validation, auto-
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
poly-lexis provides a complete solution for managing internationalization (i18n) in your applications. It offers smart translation management with automatic validation, Google Translate integration for auto-filling missing translations, and TypeScript type generation for type-safe translations.
|
|
7
|
+
poly-lexis provides a complete solution for managing internationalization (i18n) in your applications. It offers smart translation management with automatic validation, DeepL and Google Translate integration for auto-filling missing translations, and TypeScript type generation for type-safe translations.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -19,13 +19,17 @@ pnpm add poly-lexis
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
# Initialize translations in your project
|
|
22
|
+
# Initialize translations in your project (interactive setup)
|
|
23
23
|
npx poly-lexis
|
|
24
24
|
|
|
25
25
|
# Add a new translation key
|
|
26
26
|
npx poly-lexis add
|
|
27
27
|
|
|
28
|
-
# Auto-fill missing translations
|
|
28
|
+
# Auto-fill missing translations with DeepL (recommended)
|
|
29
|
+
export DEEPL_API_KEY=your_key
|
|
30
|
+
npx poly-lexis --auto-fill
|
|
31
|
+
|
|
32
|
+
# Or use Google Translate
|
|
29
33
|
export GOOGLE_TRANSLATE_API_KEY=your_key
|
|
30
34
|
npx poly-lexis --auto-fill
|
|
31
35
|
|
|
@@ -37,7 +41,8 @@ npx poly-lexis
|
|
|
37
41
|
|
|
38
42
|
- ✅ **Smart translation management** - Automatic initialization and validation
|
|
39
43
|
- ✅ **Interactive CLI** - User-friendly prompts for all operations
|
|
40
|
-
- ✅ **
|
|
44
|
+
- ✅ **Multiple providers** - DeepL (recommended) or Google Translate for auto-translation
|
|
45
|
+
- ✅ **Custom providers** - Extensible architecture for custom translation services
|
|
41
46
|
- ✅ **Type generation** - Generate TypeScript types for type-safe translations
|
|
42
47
|
- ✅ **Validation** - Detect missing or empty translation keys
|
|
43
48
|
- ✅ **Multiple namespaces** - Organize translations by feature/domain
|
|
@@ -122,8 +127,8 @@ jobs:
|
|
|
122
127
|
### CLI Options
|
|
123
128
|
|
|
124
129
|
**Smart Mode:**
|
|
125
|
-
- `-a, --auto-fill` - Auto-fill missing translations with Google Translate
|
|
126
|
-
- `--api-key <key>` -
|
|
130
|
+
- `-a, --auto-fill` - Auto-fill missing translations with DeepL or Google Translate
|
|
131
|
+
- `--api-key <key>` - Translation API key (or set DEEPL_API_KEY/GOOGLE_TRANSLATE_API_KEY env var)
|
|
127
132
|
- `-l, --language <lang>` - Process only this language
|
|
128
133
|
- `--limit <number>` - Max translations to process (default: 1000)
|
|
129
134
|
- `--skip-types` - Skip TypeScript type generation
|
|
@@ -144,7 +149,8 @@ poly-lexis uses a `.translationsrc.json` file in your project root for configura
|
|
|
144
149
|
"translationsPath": "public/static/locales",
|
|
145
150
|
"languages": ["en", "es", "fr", "de"],
|
|
146
151
|
"sourceLanguage": "en",
|
|
147
|
-
"typesOutputPath": "src/types/i18nTypes.ts"
|
|
152
|
+
"typesOutputPath": "src/types/i18nTypes.ts",
|
|
153
|
+
"provider": "deepl"
|
|
148
154
|
}
|
|
149
155
|
```
|
|
150
156
|
|
|
@@ -154,10 +160,45 @@ poly-lexis uses a `.translationsrc.json` file in your project root for configura
|
|
|
154
160
|
- `languages` - Array of language codes to support (default: `["en"]`)
|
|
155
161
|
- `sourceLanguage` - Source language for translations (default: `"en"`)
|
|
156
162
|
- `typesOutputPath` - Path to output TypeScript types (default: `src/types/i18nTypes.ts`)
|
|
163
|
+
- `provider` - Translation provider to use: `"deepl"` or `"google"` (default: `"deepl"`)
|
|
157
164
|
|
|
158
165
|
### Environment Variables
|
|
159
166
|
|
|
160
|
-
- `
|
|
167
|
+
- `DEEPL_API_KEY` - DeepL API key for auto-translation (when provider is "deepl")
|
|
168
|
+
- `GOOGLE_TRANSLATE_API_KEY` - Google Translate API key for auto-translation (when provider is "google")
|
|
169
|
+
|
|
170
|
+
### Translation Providers
|
|
171
|
+
|
|
172
|
+
**DeepL (Recommended)**
|
|
173
|
+
- Higher translation quality
|
|
174
|
+
- Supports 30+ languages
|
|
175
|
+
- Requires DeepL API key from https://www.deepl.com/pro-api
|
|
176
|
+
- Set `"provider": "deepl"` in config and `DEEPL_API_KEY` environment variable
|
|
177
|
+
|
|
178
|
+
**Google Translate**
|
|
179
|
+
- Supports 100+ languages
|
|
180
|
+
- Requires Google Cloud Translation API key
|
|
181
|
+
- Set `"provider": "google"` in config and `GOOGLE_TRANSLATE_API_KEY` environment variable
|
|
182
|
+
|
|
183
|
+
**Custom Providers**
|
|
184
|
+
You can implement custom translation providers by implementing the `TranslationProvider` interface:
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { setTranslationProvider, type TranslationProvider } from 'poly-lexis';
|
|
188
|
+
|
|
189
|
+
class MyCustomProvider implements TranslationProvider {
|
|
190
|
+
async translate(options: TranslateOptions): Promise<string> {
|
|
191
|
+
// Your translation logic here
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async translateBatch(texts: string[], sourceLang: string, targetLang: string, apiKey?: string): Promise<string[]> {
|
|
195
|
+
// Your batch translation logic here
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Set your custom provider before running auto-fill
|
|
200
|
+
setTranslationProvider(new MyCustomProvider());
|
|
201
|
+
```
|
|
161
202
|
|
|
162
203
|
### Directory Structure
|
|
163
204
|
|
|
@@ -217,7 +258,7 @@ await addTranslationKey(process.cwd(), {
|
|
|
217
258
|
key: 'HELLO',
|
|
218
259
|
value: 'Hello',
|
|
219
260
|
autoTranslate: true,
|
|
220
|
-
apiKey: process.env.GOOGLE_TRANSLATE_API_KEY
|
|
261
|
+
apiKey: process.env.DEEPL_API_KEY, // or GOOGLE_TRANSLATE_API_KEY
|
|
221
262
|
});
|
|
222
263
|
```
|
|
223
264
|
|
|
@@ -250,11 +291,27 @@ generateTranslationTypes(process.cwd());
|
|
|
250
291
|
```typescript
|
|
251
292
|
import { autoFillTranslations } from 'poly-lexis';
|
|
252
293
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
294
|
+
// The provider is automatically selected based on .translationsrc.json
|
|
295
|
+
await autoFillTranslations(process.cwd(), {
|
|
296
|
+
apiKey: process.env.DEEPL_API_KEY, // or GOOGLE_TRANSLATE_API_KEY
|
|
297
|
+
limit: 1000,
|
|
298
|
+
language: 'fr', // optional: auto-fill only this language
|
|
299
|
+
dryRun: false, // optional: preview without saving
|
|
300
|
+
});
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Using Custom Translation Providers
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
import { setTranslationProvider, autoFillTranslations } from 'poly-lexis';
|
|
307
|
+
import { MyCustomProvider } from './my-provider';
|
|
308
|
+
|
|
309
|
+
// Set your custom provider before auto-filling
|
|
310
|
+
setTranslationProvider(new MyCustomProvider());
|
|
311
|
+
|
|
312
|
+
// Now auto-fill will use your custom provider
|
|
313
|
+
await autoFillTranslations(process.cwd(), {
|
|
314
|
+
apiKey: 'your-custom-api-key',
|
|
258
315
|
limit: 1000,
|
|
259
316
|
});
|
|
260
317
|
```
|
|
@@ -306,15 +363,28 @@ src/
|
|
|
306
363
|
## Requirements
|
|
307
364
|
|
|
308
365
|
- Node.js 18+
|
|
309
|
-
- (Optional) Google Translate API key for auto-translation
|
|
366
|
+
- (Optional) DeepL API key or Google Translate API key for auto-translation
|
|
310
367
|
|
|
311
368
|
## How It Works
|
|
312
369
|
|
|
313
|
-
1. **Initialization**: Creates `.translationsrc.json` and translation directory structure
|
|
370
|
+
1. **Initialization**: Creates `.translationsrc.json` and translation directory structure with provider selection
|
|
314
371
|
2. **Validation**: Compares all language files against source language to find missing keys
|
|
315
|
-
3. **Auto-translation**: Uses Google Translate API to fill missing translations
|
|
372
|
+
3. **Auto-translation**: Uses DeepL or Google Translate API (based on config) to fill missing translations
|
|
316
373
|
4. **Type Generation**: Creates TypeScript types from translation keys for autocomplete and type safety
|
|
317
374
|
|
|
375
|
+
## API Keys
|
|
376
|
+
|
|
377
|
+
### DeepL API Key (Recommended)
|
|
378
|
+
1. Sign up at https://www.deepl.com/pro-api
|
|
379
|
+
2. Get your API key from the account dashboard
|
|
380
|
+
3. Set `DEEPL_API_KEY` environment variable or pass via `--api-key` flag
|
|
381
|
+
|
|
382
|
+
### Google Translate API Key
|
|
383
|
+
1. Create a project in Google Cloud Console
|
|
384
|
+
2. Enable the Cloud Translation API
|
|
385
|
+
3. Create credentials (API key)
|
|
386
|
+
4. Set `GOOGLE_TRANSLATE_API_KEY` environment variable or pass via `--api-key` flag
|
|
387
|
+
|
|
318
388
|
## License
|
|
319
389
|
|
|
320
390
|
MIT
|