@intl-party/cli 1.0.0 → 1.1.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/LICENSE +2 -2
- package/README.md +413 -0
- package/dist/cli.js +1267 -163
- package/dist/index.js +909 -46
- package/package.json +14 -6
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025-2026 IntlParty Team
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
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 nextjs --init
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This creates an `intl-party.config.ts` file:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
export default {
|
|
42
|
+
locales: ["en", "es", "fr"],
|
|
43
|
+
defaultLocale: "en",
|
|
44
|
+
messages: "./messages",
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Extract Translations
|
|
49
|
+
|
|
50
|
+
Extract translatable strings from your code:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
intl-party extract
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This scans your source files for translation keys like:
|
|
57
|
+
|
|
58
|
+
- `t('welcome')`
|
|
59
|
+
- `useTranslations('common')('title')`
|
|
60
|
+
- `i18nKey="description"`
|
|
61
|
+
|
|
62
|
+
### Validate Translations
|
|
63
|
+
|
|
64
|
+
Check for issues in your translations:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
intl-party check
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Reports:
|
|
71
|
+
|
|
72
|
+
- Missing translations in different locales
|
|
73
|
+
- Unused translation keys
|
|
74
|
+
- Format errors in translations
|
|
75
|
+
|
|
76
|
+
### Synchronize Translations
|
|
77
|
+
|
|
78
|
+
Sync keys across all locales:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
intl-party sync
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Commands
|
|
85
|
+
|
|
86
|
+
### `intl-party init`
|
|
87
|
+
|
|
88
|
+
Initialize IntlParty configuration in your project.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
intl-party init [options]
|
|
92
|
+
|
|
93
|
+
Options:
|
|
94
|
+
--config <path> Configuration file path (default: intl-party.config.js)
|
|
95
|
+
--force Overwrite existing configuration
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `intl-party extract`
|
|
99
|
+
|
|
100
|
+
Extract translation keys from source code.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
intl-party extract [options]
|
|
104
|
+
|
|
105
|
+
Options:
|
|
106
|
+
--config <path> Configuration file path
|
|
107
|
+
--output <path> Output directory for extracted keys
|
|
108
|
+
--dry-run Show what would be extracted without writing files
|
|
109
|
+
--verbose Show detailed extraction information
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Example output:
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
✅ Extracted 145 translation keys
|
|
116
|
+
📁 Found in 23 source files
|
|
117
|
+
🏷️ Namespaces: common (89), navigation (34), forms (22)
|
|
118
|
+
📝 Created: extracted-keys.json
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### `intl-party check`
|
|
122
|
+
|
|
123
|
+
Check for issues in translations and configuration.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
intl-party check [options]
|
|
127
|
+
|
|
128
|
+
Options:
|
|
129
|
+
--missing Check for missing translations
|
|
130
|
+
--unused Check for unused translation keys
|
|
131
|
+
--duplicates Check for duplicate keys
|
|
132
|
+
--format-errors Check for format errors in translations
|
|
133
|
+
--fix Automatically fix issues where possible
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### `intl-party check-config`
|
|
137
|
+
|
|
138
|
+
Validate your IntlParty configuration.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
intl-party check-config [options]
|
|
142
|
+
|
|
143
|
+
Options:
|
|
144
|
+
-c, --config <path> Path to config file
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `intl-party generate`
|
|
148
|
+
|
|
149
|
+
Generate translation files from templates.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
intl-party generate [options]
|
|
153
|
+
|
|
154
|
+
Options:
|
|
155
|
+
--config <path> Configuration file path
|
|
156
|
+
--locale <code> Generate for specific locale only
|
|
157
|
+
--namespace <ns> Generate for specific namespace only
|
|
158
|
+
--template <path> Custom template file
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### `intl-party sync`
|
|
162
|
+
|
|
163
|
+
Synchronize translation keys across locales.
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
intl-party sync [options]
|
|
167
|
+
|
|
168
|
+
Options:
|
|
169
|
+
--config <path> Configuration file path
|
|
170
|
+
--source <locale> Source locale to sync from (default: defaultLocale)
|
|
171
|
+
--target <locale> Target locale to sync to (sync all if not specified)
|
|
172
|
+
--add-missing Add missing keys with placeholder values
|
|
173
|
+
--remove-unused Remove unused keys
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Configuration
|
|
177
|
+
|
|
178
|
+
### Basic Configuration
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
// intl-party.config.js
|
|
182
|
+
module.exports = {
|
|
183
|
+
// Required
|
|
184
|
+
locales: ["en", "es", "fr", "de"],
|
|
185
|
+
defaultLocale: "en",
|
|
186
|
+
namespaces: ["common", "navigation", "forms"],
|
|
187
|
+
|
|
188
|
+
// Paths
|
|
189
|
+
translationsDir: "./messages", // Where translation files are stored
|
|
190
|
+
sourceDir: "./src", // Where to scan for translation usage
|
|
191
|
+
|
|
192
|
+
// File patterns
|
|
193
|
+
patterns: {
|
|
194
|
+
extract: [
|
|
195
|
+
"**/*.{ts,tsx,js,jsx}", // Files to scan for translations
|
|
196
|
+
"!**/*.test.*", // Exclude test files
|
|
197
|
+
"!**/node_modules/**", // Exclude dependencies
|
|
198
|
+
],
|
|
199
|
+
translation: "{locale}/{namespace}.json", // Translation file pattern
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Advanced Configuration
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
module.exports = {
|
|
208
|
+
locales: ["en", "es", "fr"],
|
|
209
|
+
defaultLocale: "en",
|
|
210
|
+
namespaces: ["common", "navigation"],
|
|
211
|
+
translationsDir: "./messages",
|
|
212
|
+
sourceDir: "./src",
|
|
213
|
+
|
|
214
|
+
// Extraction settings
|
|
215
|
+
extraction: {
|
|
216
|
+
// Custom function patterns to detect
|
|
217
|
+
functions: ["t", "translate", "_"],
|
|
218
|
+
|
|
219
|
+
// Hook patterns
|
|
220
|
+
hooks: ["useTranslations"],
|
|
221
|
+
|
|
222
|
+
// Component patterns
|
|
223
|
+
components: ["Trans", "Translation"],
|
|
224
|
+
|
|
225
|
+
// Key patterns (regex)
|
|
226
|
+
keyPatterns: [
|
|
227
|
+
/t\(['"`]([^'"`]+)['"`]\)/g,
|
|
228
|
+
/useTranslations\(['"`]([^'"`]+)['"`]\)/g,
|
|
229
|
+
],
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
// Validation rules
|
|
233
|
+
validation: {
|
|
234
|
+
rules: {
|
|
235
|
+
missingTranslations: "error", // error, warn, ignore
|
|
236
|
+
unusedTranslations: "warn",
|
|
237
|
+
inconsistentInterpolation: "error",
|
|
238
|
+
emptyTranslations: "warn",
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
// Required interpolation variables
|
|
242
|
+
requiredVariables: ["count", "name"],
|
|
243
|
+
|
|
244
|
+
// Allowed HTML tags in translations
|
|
245
|
+
allowedTags: ["strong", "em", "br"],
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
// Generation settings
|
|
249
|
+
generation: {
|
|
250
|
+
// Default value for missing translations
|
|
251
|
+
defaultValue: "[MISSING: {{key}}]",
|
|
252
|
+
|
|
253
|
+
// Template for new translation files
|
|
254
|
+
template: "./templates/translation.json",
|
|
255
|
+
|
|
256
|
+
// Sort keys alphabetically
|
|
257
|
+
sortKeys: true,
|
|
258
|
+
|
|
259
|
+
// Indentation in JSON files
|
|
260
|
+
indent: 2,
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Integration with Build Tools
|
|
266
|
+
|
|
267
|
+
### npm scripts
|
|
268
|
+
|
|
269
|
+
```json
|
|
270
|
+
{
|
|
271
|
+
"scripts": {
|
|
272
|
+
"i18n:extract": "intl-party extract",
|
|
273
|
+
"i18n:validate": "intl-party validate",
|
|
274
|
+
"i18n:sync": "intl-party sync",
|
|
275
|
+
"prebuild": "npm run i18n:validate"
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### CI/CD Integration
|
|
281
|
+
|
|
282
|
+
```yaml
|
|
283
|
+
# .github/workflows/i18n.yml
|
|
284
|
+
name: Internationalization
|
|
285
|
+
on: [push, pull_request]
|
|
286
|
+
|
|
287
|
+
jobs:
|
|
288
|
+
i18n:
|
|
289
|
+
runs-on: ubuntu-latest
|
|
290
|
+
steps:
|
|
291
|
+
- uses: actions/checkout@v3
|
|
292
|
+
- uses: actions/setup-node@v3
|
|
293
|
+
- run: npm ci
|
|
294
|
+
- run: npm run i18n:validate
|
|
295
|
+
- run: npm run i18n:extract --dry-run
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Pre-commit Hooks
|
|
299
|
+
|
|
300
|
+
```json
|
|
301
|
+
// .husky/pre-commit or package.json
|
|
302
|
+
{
|
|
303
|
+
"husky": {
|
|
304
|
+
"hooks": {
|
|
305
|
+
"pre-commit": "intl-party validate --strict"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## File Structure Examples
|
|
312
|
+
|
|
313
|
+
### Flat Structure
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
messages/
|
|
317
|
+
en.json
|
|
318
|
+
es.json
|
|
319
|
+
fr.json
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Namespaced Structure
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
messages/
|
|
326
|
+
en/
|
|
327
|
+
common.json
|
|
328
|
+
navigation.json
|
|
329
|
+
forms.json
|
|
330
|
+
es/
|
|
331
|
+
common.json
|
|
332
|
+
navigation.json
|
|
333
|
+
forms.json
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Custom Structure
|
|
337
|
+
|
|
338
|
+
```javascript
|
|
339
|
+
// intl-party.config.js
|
|
340
|
+
module.exports = {
|
|
341
|
+
patterns: {
|
|
342
|
+
translation: "locales/{locale}/messages/{namespace}.json",
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// Results in:
|
|
347
|
+
// locales/en/messages/common.json
|
|
348
|
+
// locales/es/messages/common.json
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Plugins and Extensions
|
|
352
|
+
|
|
353
|
+
### Custom Extractors
|
|
354
|
+
|
|
355
|
+
```javascript
|
|
356
|
+
// intl-party.config.js
|
|
357
|
+
module.exports = {
|
|
358
|
+
plugins: [
|
|
359
|
+
{
|
|
360
|
+
name: "custom-extractor",
|
|
361
|
+
extract: (content, filename) => {
|
|
362
|
+
// Custom extraction logic
|
|
363
|
+
const keys = [];
|
|
364
|
+
// ... extract keys from content
|
|
365
|
+
return keys;
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
};
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Custom Validators
|
|
373
|
+
|
|
374
|
+
```javascript
|
|
375
|
+
module.exports = {
|
|
376
|
+
plugins: [
|
|
377
|
+
{
|
|
378
|
+
name: "custom-validator",
|
|
379
|
+
validate: (translations, config) => {
|
|
380
|
+
// Custom validation logic
|
|
381
|
+
const issues = [];
|
|
382
|
+
// ... validate translations
|
|
383
|
+
return issues;
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
};
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Troubleshooting
|
|
391
|
+
|
|
392
|
+
### Common Issues
|
|
393
|
+
|
|
394
|
+
1. **Keys not extracted**: Check your function patterns in configuration
|
|
395
|
+
2. **False positives**: Use more specific regex patterns
|
|
396
|
+
3. **Missing files**: Verify translationsDir and file patterns
|
|
397
|
+
4. **Permission errors**: Ensure write access to output directories
|
|
398
|
+
|
|
399
|
+
### Debug Mode
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
intl-party extract --verbose --dry-run
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### Configuration Validation
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
intl-party check-config
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
## License
|
|
412
|
+
|
|
413
|
+
MIT © IntlParty
|