@l10nmonster/cli
v3.1.3
Published
Continuous localization for the rest of us
Maintainers
Readme
@l10nmonster/cli
Command-line interface for L10n Monster v3 - continuous localization for the rest of us.
Installation
From npm
npm install -g @l10nmonster/cliFrom source
git clone [email protected]:l10nmonster/l10nmonster.git
cd l10nmonster
npm install
npm run build
npm link --global @l10nmonster/cliGetting Started
Create a configuration file l10nmonster.config.mjs at your project root, then use the CLI commands to manage translations.
Basic Configuration
// l10nmonster.config.mjs
import { FsSource, FsTarget } from '@l10nmonster/core';
export default {
channels: [{
source: new FsSource({ globs: ['src/**/*.json'] }),
target: new FsTarget({
targetPath: (lang, resourceId) => resourceId.replace('/en/', `/${lang}/`)
})
}],
providers: [{
id: 'internal',
provider: 'InternalLeverage'
}]
};v3 Commands
Core Operations
# Analyze source content
l10n analyzeAnalyzes your sources and reports insights like repeated content, quality metrics, and translation opportunities.
# Capture source content snapshot
l10n source snapCreates a snapshot of your source content for translation workflows.
# Generate translations
l10n translateProcesses translation requests through configured providers and generates translated resources.
# Update operations and target resources
l10n ops updateUpdates target resources with latest translations and manages operation lifecycle.
Translation Memory
# Synchronize TM with providers
l10n tm syncupUploads completed translations to translation memory stores.
# Download translations from TM
l10n tm syncdown Downloads latest translations from translation memory to local stores.
# Export TM data
l10n tm exportExports translation memory data for backup or external processing.
Source Management
# List source content
l10n source listLists all detected source content with metadata and statistics.
# Query specific content
l10n source query --filter "*.json"Queries source content with filters and search criteria.
# Show untranslated content
l10n source untranslated --target esShows untranslated content for specific target languages.
Operations Management
# View operation details
l10n ops viewDisplays detailed information about current operations and their status.
# Manage jobs
l10n ops jobs --status pendingLists and manages translation jobs by status or other criteria.
# Provider operations
l10n ops providersShows configured providers and their current status.
# Delete operations
l10n ops delete --job-id abc123Removes specific operations or jobs from the system.
Legacy Commands (v2 compatibility)
# Legacy push operation
l10n pushDeprecated: Use l10n translate and l10n ops update instead.
# Legacy pull operation
l10n pullDeprecated: Use l10n tm syncdown and l10n ops update instead.
# Legacy status command
l10n statusDeprecated: Use l10n analyze for detailed insights.
Working Files
L10n Monster v3 maintains its working files in a l10nmonster/ directory at the root of the project:
- TM stores:
l10nmonster/tm/- Translation memory data - Operations:
l10nmonster/ops/- Job and task management - Snapshots:
l10nmonster/snap/- Source content snapshots - Providers:
l10nmonster/providers/- Provider-specific data
Working files are source-control friendly (JSON/JSONL files with consistent formatting) and should be checked in for team collaboration.
Advanced CLI Options
The CLI supports additional options to control behavior:
-c, --config <path>: Specify custom configuration file path-v, --verbose: Output additional debug information--dry-run: Preview operations without making changes--parallel <number>: Set parallelism level for operations--filter <pattern>: Apply filters to operations
Example Usage
# Run with custom config and high verbosity
l10n translate -c ./custom.config.mjs -v
# Preview operations without executing
l10n ops update --dry-run
# Parallel translation processing
l10n translate --parallel 4
# Filter specific content
l10n source snap --filter "components/**/*.json"v3 Configuration
ESM Configuration Format
v3 uses ESM-based configuration files (l10nmonster.config.mjs):
import { FsSource, FsTarget } from '@l10nmonster/core';
import { GptAgent } from '@l10nmonster/helpers-openai';
export default {
// Source and target channels
channels: [{
source: new FsSource({
globs: ['src/**/*.json'],
targetLangs: ['es', 'fr', 'de']
}),
target: new FsTarget({
targetPath: (lang, id) => id.replace('/en/', `/${lang}/`)
})
}],
// Translation providers
providers: [{
id: 'ai-translator',
provider: new GptAgent({ model: 'gpt-4' })
}, {
id: 'internal',
provider: 'InternalLeverage'
}],
// Content type definitions
contentTypes: [{
name: 'json',
resourceFilter: 'i18next'
}],
// Storage configuration
stores: {
tm: 'BaseJsonlTmStore',
ops: 'FsOpsStore'
}
};Multi-Channel Configuration
export default {
channels: [
{
// Web app content
source: new FsSource({ globs: ['web/src/**/*.json'] }),
target: new FsTarget({ targetPath: (lang, id) => id.replace('/src/', `/dist/${lang}/`) })
},
{
// Mobile app content
source: new FsSource({ globs: ['mobile/strings/**/*.xml'] }),
target: new FsTarget({ targetPath: (lang, id) => id.replace('/strings/', `/strings-${lang}/`) })
}
]
};Provider Chains
export default {
providers: [
{ id: 'leverage', provider: 'InternalLeverage' },
{ id: 'repetitions', provider: 'Repetition' },
{ id: 'ai', provider: new GptAgent({ model: 'gpt-4' }) },
{ id: 'fallback', provider: 'Invisicode' }
]
};Error Handling
The CLI provides comprehensive error handling with actionable messages:
# Configuration errors
Error: Configuration file not found: l10nmonster.config.mjs
Tip: Run 'l10n init' to create a basic configuration
# Provider errors
Error: OpenAI API key not configured
Tip: Set OPENAI_API_KEY environment variable or configure apiKey in provider options
# Operation errors
Error: Translation job failed for provider 'gpt-4'
Tip: Check provider configuration and API limitsPerformance Optimization
Parallel Processing
# Enable parallel operations
l10n translate --parallel 4
# Provider-specific parallelism
l10n ops update --provider-parallel 2Filtering and Batching
# Process specific file patterns
l10n translate --filter "*.json"
# Batch operations by language
l10n translate --batch-by-language
# Limit operation scope
l10n source snap --since "2024-01-01"Integration Examples
CI/CD Pipeline
# GitHub Actions example
name: Localization
on: [push, pull_request]
jobs:
l10n:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- run: npm install -g @l10nmonster/cli
- run: l10n analyze
- run: l10n translate --dry-runNPM Scripts
{
"scripts": {
"l10n:analyze": "l10n analyze",
"l10n:translate": "l10n translate",
"l10n:update": "l10n ops update",
"l10n:sync": "l10n tm syncup && l10n tm syncdown"
}
}Troubleshooting
Common Issues
Configuration not found
# Ensure config file exists and has correct name ls l10nmonster.config.mjsModule import errors
# Verify Node.js version (requires >= 22.11.0) node --versionProvider authentication
# Check environment variables echo $OPENAI_API_KEYPerformance issues
# Enable debug logging l10n translate -v
Migration from v2
Configuration Updates
- Rename config file:
l10nmonster.cjs→l10nmonster.config.mjs - Update imports: Use ESM import syntax
- Update providers: Many providers have new names and APIs
- Update commands: Some command names have changed
Command Mapping
| v2 Command | v3 Equivalent |
|------------|---------------|
| l10n push | l10n translate && l10n ops update |
| l10n pull | l10n tm syncdown && l10n ops update |
| l10n status | l10n analyze |
| l10n grandfather | Provider-based (configured in config) |
| l10n leverage | Provider-based (configured in config) |
For detailed migration guidance, see the v3 Migration Guide.
Help and Support
# Get general help
l10n help
# Get command-specific help
l10n help translate
l10n help ops
l10n help source
# Get provider information
l10n ops providers --infoFor more detailed documentation, see:
