@oxog/i18n-cli 0.1.2 โ†’ 0.2.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.
Files changed (3) hide show
  1. package/README.md +34 -242
  2. package/dist/cli.js +521 -325
  3. package/package.json +17 -7
package/README.md CHANGED
@@ -1,307 +1,99 @@
1
1
  # @oxog/i18n-cli
2
2
 
3
- Command-line interface for @oxog/i18n - extract, validate, sync, and manage your translations with ease.
4
-
5
- ## Features
6
-
7
- - ๐Ÿ“ **Extract**: Automatically extract translation keys from your source code
8
- - โœ… **Validate**: Check for missing translations and invalid keys
9
- - ๐Ÿ”„ **Sync**: Synchronize translations across multiple locale files
10
- - ๐Ÿ“Š **Stats**: View translation statistics and coverage
11
- - ๐ŸŽจ **Interactive**: User-friendly prompts and colorful output
12
- - ๐Ÿ”ง **Configurable**: Flexible configuration options
3
+ Command-line tools for [@oxog/i18n](https://www.npmjs.com/package/@oxog/i18n): extract keys
4
+ from source code, validate and sync locale files, show statistics and compile catalogs.
13
5
 
14
6
  ## Installation
15
7
 
16
8
  ```bash
17
9
  npm install -D @oxog/i18n-cli
18
- # or
19
- pnpm add -D @oxog/i18n-cli
20
- # or
21
- yarn add -D @oxog/i18n-cli
10
+ npx oxog-i18n --help
11
+ npx oxog-i18n <command> --help # options of one command
22
12
  ```
23
13
 
24
- ## Quick Start
25
-
26
- ```bash
27
- # Initialize i18n configuration
28
- npx oxog-i18n init
29
-
30
- # Extract translation keys from source code
31
- npx oxog-i18n extract
32
-
33
- # Validate translations
34
- npx oxog-i18n validate
35
-
36
- # View translation statistics
37
- npx oxog-i18n stats
38
- ```
14
+ Patterns are globs relative to the current directory (`**/` also matches zero directories,
15
+ `{a,b}` alternatives are supported). `node_modules` is skipped unless the pattern names it.
39
16
 
40
17
  ## Commands
41
18
 
42
19
  ### `init`
43
20
 
44
- Initialize i18n configuration for your project.
45
-
46
21
  ```bash
47
- npx oxog-i18n init
22
+ npx oxog-i18n init [-f react|vue|svelte|vanilla] [-t]
48
23
  ```
49
24
 
50
- This command will:
51
- - Create a configuration file (`i18n.config.js`)
52
- - Set up locale directories
53
- - Create initial translation files
54
- - Configure your preferred framework integration
25
+ Asks for the locales directory, default locale and additional locales, then writes the
26
+ locale files, `src/i18n.config.(ts|js)` (importing each catalog relative to the config
27
+ file) and, for TypeScript, `src/types/i18n.d.ts`.
55
28
 
56
29
  ### `extract`
57
30
 
58
- Extract translation keys from your source code.
59
-
60
31
  ```bash
61
32
  npx oxog-i18n extract [options]
62
33
 
63
- Options:
64
- -s, --source <patterns> Source file patterns (default: "src/**/*.{js,jsx,ts,tsx}")
65
- -o, --output <dir> Output directory for translations (default: "./locales")
66
- -l, --locales <locales> Comma-separated list of locales
67
- --dry-run Show what would be extracted without writing files
34
+ -p, --pattern <pattern> Source files (default: "src/**/*.{ts,tsx,js,jsx}")
35
+ -o, --output <path> Locale directory (default: "./src/locales")
36
+ -l, --locales <locales> Comma-separated locales (default: "en")
37
+ --prune Remove keys that are no longer used in the source
68
38
  ```
69
39
 
70
- Examples:
71
- ```bash
72
- # Extract from specific directories
73
- npx oxog-i18n extract -s "src/**/*.{ts,tsx}" -s "components/**/*.{ts,tsx}"
74
-
75
- # Extract for specific locales
76
- npx oxog-i18n extract -l en,es,fr
77
-
78
- # Dry run to preview extraction
79
- npx oxog-i18n extract --dry-run
80
- ```
40
+ Finds literal keys in `t('key')`, `i18n.t("key")`, `<T id="key">` and `<Trans id="key">`
41
+ (not `split(',')`, `import('./x')` and other calls that merely end in `t(`). Existing
42
+ translations are kept; new keys get a `[key]` placeholder. Keys that conflict with an
43
+ existing string (`user` vs `user.name`) or use `__proto__`/`constructor`/`prototype` are
44
+ skipped with a warning.
81
45
 
82
46
  ### `validate`
83
47
 
84
- Validate translation files for completeness and correctness.
85
-
86
48
  ```bash
87
- npx oxog-i18n validate [options]
88
-
89
- Options:
90
- -l, --locale <locale> Specific locale to validate
91
- -s, --source <dir> Source directory for translations
92
- --strict Fail on warnings
49
+ npx oxog-i18n validate [-p "./src/locales/**/*.json"] [-s en]
93
50
  ```
94
51
 
95
- Examples:
96
- ```bash
97
- # Validate all locales
98
- npx oxog-i18n validate
99
-
100
- # Validate specific locale
101
- npx oxog-i18n validate -l es
102
-
103
- # Strict validation
104
- npx oxog-i18n validate --strict
105
- ```
52
+ Compares every catalog with the source locale and lists missing and extra keys. Exits
53
+ with status 1 when issues are found, so it can gate CI and pre-commit hooks.
106
54
 
107
55
  ### `sync`
108
56
 
109
- Synchronize translations across locale files.
110
-
111
57
  ```bash
112
- npx oxog-i18n sync [options]
113
-
114
- Options:
115
- -s, --source <locale> Source locale to sync from (default: "en")
116
- -t, --target <locales> Target locales to sync to
117
- --remove-unused Remove keys not in source
58
+ npx oxog-i18n sync [-s en] [-t es,fr] [-p ./src/locales]
118
59
  ```
119
60
 
120
- Examples:
121
- ```bash
122
- # Sync from English to all other locales
123
- npx oxog-i18n sync -s en
124
-
125
- # Sync to specific locales
126
- npx oxog-i18n sync -s en -t es,fr,de
127
-
128
- # Clean up unused keys
129
- npx oxog-i18n sync --remove-unused
130
- ```
61
+ Adds keys that are missing in the target catalogs (copied from the source), after asking
62
+ for confirmation per locale. Existing translations are not changed.
131
63
 
132
64
  ### `stats`
133
65
 
134
- Display translation statistics and coverage.
135
-
136
66
  ```bash
137
- npx oxog-i18n stats [options]
138
-
139
- Options:
140
- -l, --locale <locale> Show stats for specific locale
141
- --json Output stats as JSON
67
+ npx oxog-i18n stats [-p ./src/locales] [-f table|json]
142
68
  ```
143
69
 
144
- Examples:
145
- ```bash
146
- # Show stats for all locales
147
- npx oxog-i18n stats
148
-
149
- # Show stats for specific locale
150
- npx oxog-i18n stats -l fr
151
-
152
- # Export stats as JSON
153
- npx oxog-i18n stats --json > translation-stats.json
154
- ```
70
+ Shows keys, words, characters and coverage per locale.
155
71
 
156
72
  ### `compile`
157
73
 
158
- Compile translations for production (optimize bundle size).
159
-
160
74
  ```bash
161
- npx oxog-i18n compile [options]
162
-
163
- Options:
164
- -s, --source <dir> Source directory for translations
165
- -o, --output <dir> Output directory for compiled translations
166
- --format <format> Output format (json, esm, cjs)
167
- ```
168
-
169
- ## Configuration
170
-
171
- Create an `i18n.config.js` file in your project root:
172
-
173
- ```javascript
174
- module.exports = {
175
- // Locales configuration
176
- locales: {
177
- default: 'en',
178
- supported: ['en', 'es', 'fr', 'de']
179
- },
180
-
181
- // Source code configuration
182
- source: {
183
- patterns: ['src/**/*.{js,jsx,ts,tsx}'],
184
- exclude: ['**/*.test.*', '**/*.spec.*']
185
- },
186
-
187
- // Translation files configuration
188
- translations: {
189
- directory: './locales',
190
- structure: 'flat', // or 'nested'
191
- format: 'json' // or 'yaml'
192
- },
193
-
194
- // Extraction configuration
195
- extraction: {
196
- keyPrefix: '',
197
- defaultValue: true,
198
- preserveWhitespace: false
199
- },
200
-
201
- // Validation rules
202
- validation: {
203
- missingKeys: 'error', // or 'warning'
204
- unusedKeys: 'warning',
205
- invalidInterpolation: 'error'
206
- }
207
- };
75
+ npx oxog-i18n compile [-i ./src/locales] [-o ./dist/locales] [-f json|js|mjs]
208
76
  ```
209
77
 
210
- ## Package.json Scripts
78
+ Writes minified catalogs (empty strings removed) and an `index` module that maps locale
79
+ names (including region tags such as `pt-BR`) to catalogs. `js` output is CommonJS.
211
80
 
212
- Add these scripts to your `package.json` for convenience:
81
+ ## CI example
213
82
 
214
83
  ```json
215
84
  {
216
85
  "scripts": {
217
86
  "i18n:extract": "oxog-i18n extract",
218
- "i18n:validate": "oxog-i18n validate",
219
- "i18n:sync": "oxog-i18n sync",
220
- "i18n:stats": "oxog-i18n stats",
221
- "i18n:check": "oxog-i18n validate --strict"
87
+ "i18n:check": "oxog-i18n validate"
222
88
  }
223
89
  }
224
90
  ```
225
91
 
226
- ## CI/CD Integration
227
-
228
- ### GitHub Actions
229
-
230
92
  ```yaml
231
- name: i18n
232
- on: [push, pull_request]
233
-
234
- jobs:
235
- validate-translations:
236
- runs-on: ubuntu-latest
237
- steps:
238
- - uses: actions/checkout@v3
239
- - uses: actions/setup-node@v3
240
- - run: npm ci
241
- - run: npm run i18n:validate -- --strict
242
- ```
243
-
244
- ### Pre-commit Hook
245
-
246
- ```bash
247
- # .husky/pre-commit
248
- #!/bin/sh
249
- . "$(dirname "$0")/_/husky.sh"
250
-
251
- npm run i18n:check
252
- ```
253
-
254
- ## Advanced Usage
255
-
256
- ### Custom Extractors
257
-
258
- Register custom extraction patterns:
259
-
260
- ```javascript
261
- // i18n.config.js
262
- module.exports = {
263
- extractors: [
264
- {
265
- pattern: /customT\(['"]([^'"]+)['"]\)/g,
266
- keyIndex: 1
267
- }
268
- ]
269
- };
270
- ```
271
-
272
- ### Namespace Support
273
-
274
- Organize translations by namespace:
275
-
276
- ```bash
277
- npx oxog-i18n extract --namespace common
278
- npx oxog-i18n extract --namespace features/auth
279
- ```
280
-
281
- ### Plugin System
282
-
283
- Extend CLI functionality with plugins:
284
-
285
- ```javascript
286
- // i18n.config.js
287
- module.exports = {
288
- plugins: [
289
- '@oxog/i18n-plugin-json-sort',
290
- '@oxog/i18n-plugin-translate-missing'
291
- ]
292
- };
93
+ - run: npm ci
94
+ - run: npm run i18n:check
293
95
  ```
294
96
 
295
97
  ## License
296
98
 
297
99
  MIT ยฉ Ersin Koรง
298
-
299
- ## Contributing
300
-
301
- Contributions are welcome! Please read our [Contributing Guide](https://github.com/ersinkoc/i18n/blob/main/CONTRIBUTING.md) for details.
302
-
303
- ## Links
304
-
305
- - [GitHub Repository](https://github.com/ersinkoc/i18n)
306
- - [NPM Package](https://www.npmjs.com/package/@oxog/i18n-cli)
307
- - [Documentation](https://github.com/ersinkoc/i18n#readme)