locale-builder
v1.0.0
Published
A CLI tool to automate internationalization (i18n) file translations. It takes a single English source file and generates translated locale files for multiple languages using open-source translation engines.
Maintainers
Readme
locale-builder
A CLI tool to automate internationalization (i18n) file translations. It takes a single English source file and generates translated locale files for multiple languages using open-source translation engines.
Features
- Single Source of Truth: Manage only your English file.
- Nested Key Support: Preserves deep object structures.
- Incremental Translation: Only translates new or missing keys.
- Smart Merging: Keeps existing manual translations.
- Multiple Formats: Supports JSON, YAML, and TypeScript exports.
- Online Translation: Uses Google Translate (via
google-translate-api-x) - no API key required. - Type Preservation: Preserves non-string values (numbers, booleans) without modification.
Installation
npm install -g locale-builder
# or run directly with npx
npx locale-builder --helpUsage
Basic Usage
Translate en.json to Spanish and French using Google Translate:
locale-builder translate locales/en.json --target es,frOptions
| Option | Alias | Description | Default |
| ---------- | ----- | ---------------------------------- | -------------- |
| --target | -t | Target languages (comma separated) | Required |
| --output | -o | Output directory | Same as source |
| --mock | | Use mock translator (for testing) | false |
Examples
Using Google Translate:
locale-builder translate src/locales/en.ts -t de,itUsing Mock mode (for testing structure):
locale-builder translate en.json -t es --mockProject Structure
src/core: Core logic and file handlers.src/adapters: Translation engine adapters.src/utils: Helper utilities.
Development
- Clone the repo
npm installnpm run buildnpm test
License
MIT
