@logistically/i18n-cli
Version:
Enterprise-grade CLI tool for extracting and managing translations in Logistically microservices
690 lines (536 loc) • 13.8 kB
Markdown
> Complete configuration guide for @logistically/i18n-cli
1. [Overview](
2. [Configuration Sources](
3. [Environment Variables](
4. [Configuration File](
5. [Command Line Options](
6. [Environment-Specific Configs](
7. [Best Practices](
8. [Validation](
The CLI supports multiple configuration sources with a hierarchical precedence system:
1. **Command-line arguments** (highest priority)
2. **Environment variables**
3. **Configuration file** (`.i18n-cli.json`)
4. **Default values** (lowest priority)
Override any configuration via command-line options:
```bash
i18n extract --log-level debug
i18n extract --concurrency 8
i18n extract --max-file-size 100
```
Set environment variables for persistent configuration:
```bash
export NODE_ENV=production
export LOG_LEVEL=warn
export LOG_FORMAT=json
export LOG_OUTPUT=both
export MAX_CONCURRENCY=8
export MAX_FILE_SIZE=50
export VALIDATE_INPUTS=true
export SANITIZE_OUTPUTS=true
```
Create `.i18n-cli.json` in your project root:
```json
{
"version": "1.0.0",
"environment": "production",
"logging": {
"level": "warn",
"format": "json",
"output": "both",
"filePath": "/var/log/i18n-cli.log"
},
"performance": {
"maxConcurrency": 8,
"maxFileSize": 50,
"timeout": 600
},
"security": {
"validateInputs": true,
"sanitizeOutputs": true,
"maxKeyLength": 200
},
"features": {
"enableValidation": true,
"enableBackup": true,
"enableDryRun": true,
"enableProgressBar": true
}
}
```
| Variable | Description | Default | Example |
|----------|-------------|---------|---------|
| `NODE_ENV` | Environment | `development` | `production` |
| `LOG_LEVEL` | Log level | `info` | `debug` |
| `LOG_FORMAT` | Log format | `text` | `json` |
| `LOG_OUTPUT` | Log output | `console` | `both` |
| `LOG_FILE` | Log file path | - | `/var/log/i18n-cli.log` |
| Variable | Description | Default | Example |
|----------|-------------|---------|---------|
| `MAX_CONCURRENCY` | Max concurrent processing | `4` | `8` |
| `MAX_FILE_SIZE` | Max file size in MB | `50` | `100` |
| `TIMEOUT` | Operation timeout in seconds | `300` | `600` |
| Variable | Description | Default | Example |
|----------|-------------|---------|---------|
| `VALIDATE_INPUTS` | Enable input validation | `true` | `true` |
| `SANITIZE_OUTPUTS` | Enable output sanitization | `true` | `true` |
| `MAX_KEY_LENGTH` | Max translation key length | `200` | `100` |
| Variable | Description | Default | Example |
|----------|-------------|---------|---------|
| `ENABLE_VALIDATION` | Enable validation features | `true` | `true` |
| `ENABLE_BACKUP` | Enable backup features | `true` | `true` |
| `ENABLE_DRY_RUN` | Enable dry run features | `true` | `true` |
| `ENABLE_PROGRESS_BAR` | Enable progress bar | `true` | `true` |
The configuration file uses JSON format with the following structure:
```json
{
"version": "1.0.0",
"environment": "production",
"logging": {
"level": "warn",
"format": "json",
"output": "both",
"filePath": "/var/log/i18n-cli.log"
},
"performance": {
"maxConcurrency": 8,
"maxFileSize": 50,
"timeout": 600
},
"security": {
"validateInputs": true,
"sanitizeOutputs": true,
"maxKeyLength": 200
},
"features": {
"enableValidation": true,
"enableBackup": true,
"enableDryRun": true,
"enableProgressBar": true
}
}
```
```json
{
"logging": {
"level": "warn", // debug, info, warn, error
"format": "json", // text, json
"output": "both", // console, file, both
"filePath": "/var/log/i18n-cli.log" // Log file path
}
}
```
**Options:**
- `level`: Log level (`debug`, `info`, `warn`, `error`)
- `format`: Log format (`text`, `json`)
- `output`: Log output (`console`, `file`, `both`)
- `filePath`: Log file path (required when output is `file` or `both`)
#### Performance Configuration
```json
{
"performance": {
"maxConcurrency": 8, // Max concurrent file processing
"maxFileSize": 50, // Max file size in MB
"timeout": 600 // Operation timeout in seconds
}
}
```
**Options:**
- `maxConcurrency`: Maximum number of files to process concurrently (1-20)
- `maxFileSize`: Maximum file size to process in MB (1-100)
- `timeout`: Operation timeout in seconds (60-3600)
#### Security Configuration
```json
{
"security": {
"validateInputs": true, // Enable input validation
"sanitizeOutputs": true, // Enable output sanitization
"maxKeyLength": 200 // Max translation key length
}
}
```
**Options:**
- `validateInputs`: Enable comprehensive input validation
- `sanitizeOutputs`: Enable output sanitization for security
- `maxKeyLength`: Maximum allowed translation key length (50-500)
#### Features Configuration
```json
{
"features": {
"enableValidation": true, // Enable validation features
"enableBackup": true, // Enable backup features
"enableDryRun": true, // Enable dry run features
"enableProgressBar": true // Enable progress bar
}
}
```
**Options:**
- `enableValidation`: Enable all validation features
- `enableBackup`: Enable automatic backup creation
- `enableDryRun`: Enable dry run mode for testing
- `enableProgressBar`: Enable progress tracking
All commands support these global options:
```bash
i18n extract --verbose
i18n extract --log-level debug
i18n extract --config ./custom-config.json
i18n extract --env production
```
```bash
i18n extract --patterns "*.ts,*.js"
i18n extract --ignore "node_modules/**,dist/**"
i18n extract --output my-translations.json
i18n extract --max-file-size 100 --concurrency 8
i18n extract --validate --max-key-length 100
i18n extract --validate-inputs --sanitize-outputs
```
```bash
i18n generate --input translation-keys.json
i18n generate --languages en,fr,de
i18n generate --output ./translations
i18n generate --format json
i18n generate --template --backup
```
```bash
i18n replace --input translation-keys.json
i18n replace --patterns "*.ts,*.js"
i18n replace --dry-run --backup
i18n replace --preserve-formatting
```
```json
{
"environment": "development",
"logging": {
"level": "debug",
"format": "text",
"output": "console"
},
"performance": {
"maxConcurrency": 2,
"maxFileSize": 10,
"timeout": 300
},
"security": {
"validateInputs": true,
"sanitizeOutputs": false,
"maxKeyLength": 200
},
"features": {
"enableValidation": true,
"enableBackup": false,
"enableDryRun": true,
"enableProgressBar": true
}
}
```
```json
{
"environment": "staging",
"logging": {
"level": "info",
"format": "json",
"output": "both",
"filePath": "/var/log/i18n-cli-staging.log"
},
"performance": {
"maxConcurrency": 4,
"maxFileSize": 25,
"timeout": 600
},
"security": {
"validateInputs": true,
"sanitizeOutputs": true,
"maxKeyLength": 200
},
"features": {
"enableValidation": true,
"enableBackup": true,
"enableDryRun": true,
"enableProgressBar": true
}
}
```
```json
{
"environment": "production",
"logging": {
"level": "warn",
"format": "json",
"output": "both",
"filePath": "/var/log/i18n-cli.log"
},
"performance": {
"maxConcurrency": 8,
"maxFileSize": 50,
"timeout": 600
},
"security": {
"validateInputs": true,
"sanitizeOutputs": true,
"maxKeyLength": 200
},
"features": {
"enableValidation": true,
"enableBackup": true,
"enableDryRun": false,
"enableProgressBar": true
}
}
```
Use different configurations for different environments:
```bash
NODE_ENV=development i18n extract
NODE_ENV=staging i18n extract
NODE_ENV=production i18n extract
```
Always enable security features in production:
```json
{
"security": {
"validateInputs": true,
"sanitizeOutputs": true,
"maxKeyLength": 200
}
}
```
Adjust performance settings based on your infrastructure:
```json
{
"performance": {
"maxConcurrency": 8, // Adjust based on CPU cores
"maxFileSize": 50, // Adjust based on memory
"timeout": 600 // Adjust based on network
}
}
```
Use structured logging for better monitoring:
```json
{
"logging": {
"level": "warn",
"format": "json",
"output": "both",
"filePath": "/var/log/i18n-cli.log"
}
}
```
Enable validation and backup for data integrity:
```json
{
"features": {
"enableValidation": true,
"enableBackup": true,
"enableDryRun": true,
"enableProgressBar": true
}
}
```
Validate your configuration:
```bash
i18n config validate
i18n config validate --config ./my-config.json
i18n config validate --verbose
```
The CLI validates configuration according to these rules:
- `level` must be one of: `debug`, `info`, `warn`, `error`
- `format` must be one of: `text`, `json`
- `output` must be one of: `console`, `file`, `both`
- `filePath` is required when `output` is `file` or `both`
- `maxConcurrency` must be between 1 and 20
- `maxFileSize` must be between 1 and 100 MB
- `timeout` must be between 60 and 3600 seconds
- `maxKeyLength` must be between 50 and 500 characters
- `validateInputs` and `sanitizeOutputs` must be boolean values
Common validation errors and solutions:
```bash
Invalid log level: 'invalid'
i18n config set logging.level info
```
```bash
Max concurrency must be between 1 and 20
i18n config set performance.maxConcurrency 8
```
```bash
Log file path is required when output is 'file' or 'both'
i18n config set logging.filePath /var/log/i18n-cli.log
```
```bash
i18n config show
i18n config show --verbose
i18n config show --section logging
```
```bash
i18n config set logging.level debug
i18n config set performance.maxConcurrency 8
i18n config set security.validateInputs true
```
```bash
i18n config reset
i18n config reset --section logging
```
```json
{
"version": "1.0.0",
"environment": "production",
"logging": {
"level": "warn",
"format": "json",
"output": "both",
"filePath": "/var/log/i18n-cli.log"
},
"performance": {
"maxConcurrency": 8,
"maxFileSize": 50,
"timeout": 600
},
"security": {
"validateInputs": true,
"sanitizeOutputs": true,
"maxKeyLength": 200
},
"features": {
"enableValidation": true,
"enableBackup": true,
"enableDryRun": false,
"enableProgressBar": true
}
}
```
```bash
export NODE_ENV=production
export LOG_LEVEL=warn
export LOG_FORMAT=json
export LOG_OUTPUT=both
export LOG_FILE=/var/log/i18n-cli.log
export MAX_CONCURRENCY=8
export MAX_FILE_SIZE=50
export TIMEOUT=600
export VALIDATE_INPUTS=true
export SANITIZE_OUTPUTS=true
export MAX_KEY_LENGTH=200
export ENABLE_VALIDATION=true
export ENABLE_BACKUP=true
export ENABLE_DRY_RUN=false
export ENABLE_PROGRESS_BAR=true
i18n extract --validate
```
```dockerfile
FROM node:18-alpine
RUN npm install -g @logistically/i18n-cli
ENV NODE_ENV=production
ENV LOG_LEVEL=warn
ENV LOG_FORMAT=json
ENV MAX_CONCURRENCY=8
ENV VALIDATE_INPUTS=true
RUN mkdir -p /var/log
WORKDIR /app
COPY .i18n-cli.json .
CMD ["i18n", "extract"]
```
---
**For more information, see the [User Guide](./USER_GUIDE.md) or [API Reference](./API_REFERENCE.md).**