@oxog/i18n-cli 0.1.1 โ†’ 0.1.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.
Files changed (2) hide show
  1. package/README.md +307 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,307 @@
1
+ # @oxog/i18n-cli
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
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install -D @oxog/i18n-cli
18
+ # or
19
+ pnpm add -D @oxog/i18n-cli
20
+ # or
21
+ yarn add -D @oxog/i18n-cli
22
+ ```
23
+
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
+ ```
39
+
40
+ ## Commands
41
+
42
+ ### `init`
43
+
44
+ Initialize i18n configuration for your project.
45
+
46
+ ```bash
47
+ npx oxog-i18n init
48
+ ```
49
+
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
55
+
56
+ ### `extract`
57
+
58
+ Extract translation keys from your source code.
59
+
60
+ ```bash
61
+ npx oxog-i18n extract [options]
62
+
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
68
+ ```
69
+
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
+ ```
81
+
82
+ ### `validate`
83
+
84
+ Validate translation files for completeness and correctness.
85
+
86
+ ```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
93
+ ```
94
+
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
+ ```
106
+
107
+ ### `sync`
108
+
109
+ Synchronize translations across locale files.
110
+
111
+ ```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
118
+ ```
119
+
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
+ ```
131
+
132
+ ### `stats`
133
+
134
+ Display translation statistics and coverage.
135
+
136
+ ```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
142
+ ```
143
+
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
+ ```
155
+
156
+ ### `compile`
157
+
158
+ Compile translations for production (optimize bundle size).
159
+
160
+ ```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
+ };
208
+ ```
209
+
210
+ ## Package.json Scripts
211
+
212
+ Add these scripts to your `package.json` for convenience:
213
+
214
+ ```json
215
+ {
216
+ "scripts": {
217
+ "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"
222
+ }
223
+ }
224
+ ```
225
+
226
+ ## CI/CD Integration
227
+
228
+ ### GitHub Actions
229
+
230
+ ```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
+ };
293
+ ```
294
+
295
+ ## License
296
+
297
+ 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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxog/i18n-cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "CLI tools for @oxog/i18n",
5
5
  "author": "Ersin Koรง",
6
6
  "license": "MIT",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@oxog/i18n": "0.1.1"
20
+ "@oxog/i18n": "0.1.2"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^20.11.5",