@intl-party/cli 1.0.0 → 1.0.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/README.md +431 -0
- package/dist/cli.js +2 -2
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# @intl-party/cli
|
|
2
|
+
|
|
3
|
+
Command-line interface for IntlParty - extract, validate, and manage translations in your projects.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔍 **Extract translations** - Automatically find translatable strings in your code
|
|
8
|
+
- ✅ **Validate translations** - Check for missing keys, unused translations, and consistency
|
|
9
|
+
- 🌐 **Generate translations** - Create translation files from extracted keys
|
|
10
|
+
- 🔄 **Sync translations** - Keep translation files in sync across locales
|
|
11
|
+
- ⚙️ **Configurable** - Flexible configuration for different project structures
|
|
12
|
+
- 📊 **Reports** - Detailed reports on translation coverage and issues
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @intl-party/cli
|
|
18
|
+
# or
|
|
19
|
+
pnpm add -g @intl-party/cli
|
|
20
|
+
# or
|
|
21
|
+
yarn global add @intl-party/cli
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or install locally in your project:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install --save-dev @intl-party/cli
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Initialize Configuration
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
intl-party init
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This creates an `intl-party.config.js` file:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
module.exports = {
|
|
42
|
+
locales: ["en", "es", "fr"],
|
|
43
|
+
defaultLocale: "en",
|
|
44
|
+
namespaces: ["common", "navigation"],
|
|
45
|
+
translationsDir: "./messages",
|
|
46
|
+
sourceDir: "./src",
|
|
47
|
+
patterns: {
|
|
48
|
+
extract: ["**/*.{ts,tsx,js,jsx}", "!**/*.test.*", "!**/node_modules/**"],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Extract Translations
|
|
54
|
+
|
|
55
|
+
Extract translatable strings from your code:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
intl-party extract
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This scans your source files for translation keys like:
|
|
62
|
+
|
|
63
|
+
- `t('welcome')`
|
|
64
|
+
- `useTranslations('common')('title')`
|
|
65
|
+
- `<Trans i18nKey="description" />`
|
|
66
|
+
|
|
67
|
+
### Validate Translations
|
|
68
|
+
|
|
69
|
+
Check for issues in your translations:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
intl-party validate
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Reports:
|
|
76
|
+
|
|
77
|
+
- Missing translations in different locales
|
|
78
|
+
- Unused translation keys
|
|
79
|
+
- Inconsistent interpolation variables
|
|
80
|
+
- Invalid pluralization forms
|
|
81
|
+
|
|
82
|
+
### Generate Translation Files
|
|
83
|
+
|
|
84
|
+
Create missing translation files:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
intl-party generate
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Sync Translations
|
|
91
|
+
|
|
92
|
+
Sync keys across all locales:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
intl-party sync
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Commands
|
|
99
|
+
|
|
100
|
+
### `intl-party init`
|
|
101
|
+
|
|
102
|
+
Initialize IntlParty configuration in your project.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
intl-party init [options]
|
|
106
|
+
|
|
107
|
+
Options:
|
|
108
|
+
--config <path> Configuration file path (default: intl-party.config.js)
|
|
109
|
+
--force Overwrite existing configuration
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### `intl-party extract`
|
|
113
|
+
|
|
114
|
+
Extract translation keys from source code.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
intl-party extract [options]
|
|
118
|
+
|
|
119
|
+
Options:
|
|
120
|
+
--config <path> Configuration file path
|
|
121
|
+
--output <path> Output directory for extracted keys
|
|
122
|
+
--dry-run Show what would be extracted without writing files
|
|
123
|
+
--verbose Show detailed extraction information
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Example output:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
✅ Extracted 145 translation keys
|
|
130
|
+
📁 Found in 23 source files
|
|
131
|
+
🏷️ Namespaces: common (89), navigation (34), forms (22)
|
|
132
|
+
📝 Created: extracted-keys.json
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `intl-party validate`
|
|
136
|
+
|
|
137
|
+
Validate existing translations.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
intl-party validate [options]
|
|
141
|
+
|
|
142
|
+
Options:
|
|
143
|
+
--config <path> Configuration file path
|
|
144
|
+
--locale <code> Validate specific locale only
|
|
145
|
+
--strict Fail on warnings
|
|
146
|
+
--format <type> Output format: text, json, junit (default: text)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Example output:
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
🔍 Validating translations...
|
|
153
|
+
|
|
154
|
+
❌ Missing translations (es):
|
|
155
|
+
- common.welcome
|
|
156
|
+
- navigation.home
|
|
157
|
+
|
|
158
|
+
⚠️ Unused translations (en):
|
|
159
|
+
- common.oldKey
|
|
160
|
+
|
|
161
|
+
✅ All interpolation variables match
|
|
162
|
+
📊 Coverage: en (100%), es (87%), fr (92%)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### `intl-party generate`
|
|
166
|
+
|
|
167
|
+
Generate translation files from templates.
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
intl-party generate [options]
|
|
171
|
+
|
|
172
|
+
Options:
|
|
173
|
+
--config <path> Configuration file path
|
|
174
|
+
--locale <code> Generate for specific locale only
|
|
175
|
+
--namespace <ns> Generate for specific namespace only
|
|
176
|
+
--template <path> Custom template file
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### `intl-party sync`
|
|
180
|
+
|
|
181
|
+
Synchronize translation keys across locales.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
intl-party sync [options]
|
|
185
|
+
|
|
186
|
+
Options:
|
|
187
|
+
--config <path> Configuration file path
|
|
188
|
+
--source <locale> Source locale to sync from (default: defaultLocale)
|
|
189
|
+
--target <locale> Target locale to sync to (sync all if not specified)
|
|
190
|
+
--add-missing Add missing keys with placeholder values
|
|
191
|
+
--remove-unused Remove unused keys
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Configuration
|
|
195
|
+
|
|
196
|
+
### Basic Configuration
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
// intl-party.config.js
|
|
200
|
+
module.exports = {
|
|
201
|
+
// Required
|
|
202
|
+
locales: ["en", "es", "fr", "de"],
|
|
203
|
+
defaultLocale: "en",
|
|
204
|
+
namespaces: ["common", "navigation", "forms"],
|
|
205
|
+
|
|
206
|
+
// Paths
|
|
207
|
+
translationsDir: "./messages", // Where translation files are stored
|
|
208
|
+
sourceDir: "./src", // Where to scan for translation usage
|
|
209
|
+
|
|
210
|
+
// File patterns
|
|
211
|
+
patterns: {
|
|
212
|
+
extract: [
|
|
213
|
+
"**/*.{ts,tsx,js,jsx}", // Files to scan for translations
|
|
214
|
+
"!**/*.test.*", // Exclude test files
|
|
215
|
+
"!**/node_modules/**", // Exclude dependencies
|
|
216
|
+
],
|
|
217
|
+
translation: "{locale}/{namespace}.json", // Translation file pattern
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Advanced Configuration
|
|
223
|
+
|
|
224
|
+
```javascript
|
|
225
|
+
module.exports = {
|
|
226
|
+
locales: ["en", "es", "fr"],
|
|
227
|
+
defaultLocale: "en",
|
|
228
|
+
namespaces: ["common", "navigation"],
|
|
229
|
+
translationsDir: "./messages",
|
|
230
|
+
sourceDir: "./src",
|
|
231
|
+
|
|
232
|
+
// Extraction settings
|
|
233
|
+
extraction: {
|
|
234
|
+
// Custom function patterns to detect
|
|
235
|
+
functions: ["t", "translate", "_"],
|
|
236
|
+
|
|
237
|
+
// Hook patterns
|
|
238
|
+
hooks: ["useTranslations"],
|
|
239
|
+
|
|
240
|
+
// Component patterns
|
|
241
|
+
components: ["Trans", "Translation"],
|
|
242
|
+
|
|
243
|
+
// Key patterns (regex)
|
|
244
|
+
keyPatterns: [
|
|
245
|
+
/t\(['"`]([^'"`]+)['"`]\)/g,
|
|
246
|
+
/useTranslations\(['"`]([^'"`]+)['"`]\)/g,
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
// Validation rules
|
|
251
|
+
validation: {
|
|
252
|
+
rules: {
|
|
253
|
+
missingTranslations: "error", // error, warn, ignore
|
|
254
|
+
unusedTranslations: "warn",
|
|
255
|
+
inconsistentInterpolation: "error",
|
|
256
|
+
emptyTranslations: "warn",
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
// Required interpolation variables
|
|
260
|
+
requiredVariables: ["count", "name"],
|
|
261
|
+
|
|
262
|
+
// Allowed HTML tags in translations
|
|
263
|
+
allowedTags: ["strong", "em", "br"],
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
// Generation settings
|
|
267
|
+
generation: {
|
|
268
|
+
// Default value for missing translations
|
|
269
|
+
defaultValue: "[MISSING: {{key}}]",
|
|
270
|
+
|
|
271
|
+
// Template for new translation files
|
|
272
|
+
template: "./templates/translation.json",
|
|
273
|
+
|
|
274
|
+
// Sort keys alphabetically
|
|
275
|
+
sortKeys: true,
|
|
276
|
+
|
|
277
|
+
// Indentation in JSON files
|
|
278
|
+
indent: 2,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Integration with Build Tools
|
|
284
|
+
|
|
285
|
+
### npm scripts
|
|
286
|
+
|
|
287
|
+
```json
|
|
288
|
+
{
|
|
289
|
+
"scripts": {
|
|
290
|
+
"i18n:extract": "intl-party extract",
|
|
291
|
+
"i18n:validate": "intl-party validate",
|
|
292
|
+
"i18n:sync": "intl-party sync",
|
|
293
|
+
"prebuild": "npm run i18n:validate"
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### CI/CD Integration
|
|
299
|
+
|
|
300
|
+
```yaml
|
|
301
|
+
# .github/workflows/i18n.yml
|
|
302
|
+
name: Internationalization
|
|
303
|
+
on: [push, pull_request]
|
|
304
|
+
|
|
305
|
+
jobs:
|
|
306
|
+
i18n:
|
|
307
|
+
runs-on: ubuntu-latest
|
|
308
|
+
steps:
|
|
309
|
+
- uses: actions/checkout@v3
|
|
310
|
+
- uses: actions/setup-node@v3
|
|
311
|
+
- run: npm ci
|
|
312
|
+
- run: npm run i18n:validate
|
|
313
|
+
- run: npm run i18n:extract --dry-run
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Pre-commit Hooks
|
|
317
|
+
|
|
318
|
+
```json
|
|
319
|
+
// .husky/pre-commit or package.json
|
|
320
|
+
{
|
|
321
|
+
"husky": {
|
|
322
|
+
"hooks": {
|
|
323
|
+
"pre-commit": "intl-party validate --strict"
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## File Structure Examples
|
|
330
|
+
|
|
331
|
+
### Flat Structure
|
|
332
|
+
|
|
333
|
+
```
|
|
334
|
+
messages/
|
|
335
|
+
en.json
|
|
336
|
+
es.json
|
|
337
|
+
fr.json
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Namespaced Structure
|
|
341
|
+
|
|
342
|
+
```
|
|
343
|
+
messages/
|
|
344
|
+
en/
|
|
345
|
+
common.json
|
|
346
|
+
navigation.json
|
|
347
|
+
forms.json
|
|
348
|
+
es/
|
|
349
|
+
common.json
|
|
350
|
+
navigation.json
|
|
351
|
+
forms.json
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Custom Structure
|
|
355
|
+
|
|
356
|
+
```javascript
|
|
357
|
+
// intl-party.config.js
|
|
358
|
+
module.exports = {
|
|
359
|
+
patterns: {
|
|
360
|
+
translation: "locales/{locale}/messages/{namespace}.json",
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
// Results in:
|
|
365
|
+
// locales/en/messages/common.json
|
|
366
|
+
// locales/es/messages/common.json
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Plugins and Extensions
|
|
370
|
+
|
|
371
|
+
### Custom Extractors
|
|
372
|
+
|
|
373
|
+
```javascript
|
|
374
|
+
// intl-party.config.js
|
|
375
|
+
module.exports = {
|
|
376
|
+
plugins: [
|
|
377
|
+
{
|
|
378
|
+
name: "custom-extractor",
|
|
379
|
+
extract: (content, filename) => {
|
|
380
|
+
// Custom extraction logic
|
|
381
|
+
const keys = [];
|
|
382
|
+
// ... extract keys from content
|
|
383
|
+
return keys;
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
};
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Custom Validators
|
|
391
|
+
|
|
392
|
+
```javascript
|
|
393
|
+
module.exports = {
|
|
394
|
+
plugins: [
|
|
395
|
+
{
|
|
396
|
+
name: "custom-validator",
|
|
397
|
+
validate: (translations, config) => {
|
|
398
|
+
// Custom validation logic
|
|
399
|
+
const issues = [];
|
|
400
|
+
// ... validate translations
|
|
401
|
+
return issues;
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
};
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## Troubleshooting
|
|
409
|
+
|
|
410
|
+
### Common Issues
|
|
411
|
+
|
|
412
|
+
1. **Keys not extracted**: Check your function patterns in configuration
|
|
413
|
+
2. **False positives**: Use more specific regex patterns
|
|
414
|
+
3. **Missing files**: Verify translationsDir and file patterns
|
|
415
|
+
4. **Permission errors**: Ensure write access to output directories
|
|
416
|
+
|
|
417
|
+
### Debug Mode
|
|
418
|
+
|
|
419
|
+
```bash
|
|
420
|
+
intl-party extract --verbose --dry-run
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Configuration Validation
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
intl-party check-config
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## License
|
|
430
|
+
|
|
431
|
+
MIT © IntlParty
|
package/dist/cli.js
CHANGED
|
@@ -45,8 +45,8 @@ var require_package = __commonJS({
|
|
|
45
45
|
scripts: {
|
|
46
46
|
build: "tsup src/cli.ts src/index.ts --format cjs",
|
|
47
47
|
dev: "tsup src/cli.ts src/index.ts --format cjs --dts --watch",
|
|
48
|
-
test: "vitest",
|
|
49
|
-
"test:watch": "vitest
|
|
48
|
+
test: "vitest --run",
|
|
49
|
+
"test:watch": "vitest",
|
|
50
50
|
lint: "eslint src --ext .ts",
|
|
51
51
|
typecheck: "tsc --noEmit",
|
|
52
52
|
clean: "rm -rf dist"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intl-party/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Command-line interface for IntlParty - validation, extraction, and management tools",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"fs-extra": "^11.2.0",
|
|
29
29
|
"ora": "^7.0.1",
|
|
30
30
|
"inquirer": "^9.2.12",
|
|
31
|
-
"@intl-party/core": "1.0.
|
|
31
|
+
"@intl-party/core": "1.0.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup src/cli.ts src/index.ts --format cjs",
|
|
50
50
|
"dev": "tsup src/cli.ts src/index.ts --format cjs --dts --watch",
|
|
51
|
-
"test": "vitest",
|
|
52
|
-
"test:watch": "vitest
|
|
51
|
+
"test": "vitest --run",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
53
|
"lint": "eslint src --ext .ts",
|
|
54
54
|
"typecheck": "tsc --noEmit",
|
|
55
55
|
"clean": "rm -rf dist"
|