@marbulinek/translatte
v1.0.1
Published
Automated translation generator for JavaScript/TypeScript projects (Angular, React, Vue) using Lingva Translate API
Maintainers
Readme
TransLatté
Automatic translation file generator for JavaScript/TypeScript projects.
Install
npm install --save-dev @marbulinek/translatteOr globally:
npm install -g @marbulinek/translatteUsage
- Run
npx translatte initand edit the generated config file. - Add your source translation file (e.g.,
src/i18n/en.json). - Run
npx translatte generateto create translations.
Command-line:
translatte generate --source en --targets es,fr,de --input ./src/i18n/en.json --output ./src/i18nAs npm script:
Add to your package.json:
{
"scripts": {
"translate": "npm run translatte generate"
}
}Then run:
npm run translateConfiguration
TransLatté uses a translatte.config.json file for configuration. Run npx translatte init to create one.
Basic Configuration
For a single translation source:
{
"sourceLanguage": "en",
"targetLanguages": ["es", "fr", "de", "it", "pt", "ja", "zh"],
"inputFile": "./src/assets/i18n/en.json",
"outputDir": "./src/assets/i18n"
}Configuration Options:
sourceLanguage: The language code of your source translations (e.g., "en")targetLanguages: Array of language codes to translate toinputFile: Path to your source translation fileoutputDir: Directory where translated files will be createdlingvaInstance: (Optional) Custom Lingva instance URLpreserveInterpolation: (Optional) Keep interpolation placeholders untranslated (default: true)interpolationPattern: (Optional) Regex pattern to match placeholdersenableCache: (Optional) Enable translation caching for faster re-runs (default: true)
Multi-Module Configuration
For modular applications (Angular feature modules, React code-splitting, etc.):
{
"sourceLanguage": "en",
"targetLanguages": ["es", "fr", "de", "it"],
"sources": [
{
"name": "Core Module",
"inputFile": "./src/assets/i18n/en.json",
"outputDir": "./src/assets/i18n"
},
{
"name": "Auth Module",
"inputFile": "./src/app/auth/i18n/en.json",
"outputDir": "./src/app/auth/i18n"
},
{
"name": "Dashboard Module",
"inputFile": "./src/app/dashboard/i18n/en.json",
"outputDir": "./src/app/dashboard/i18n"
}
]
}Multi-Module Options:
sources: Array of translation sources, each with:name: Descriptive name for the moduleinputFile: Path to the module's source translation fileoutputDir: Directory for the module's translated files
Placeholder/Interpolation Support
TransLatté preserves common interpolation patterns used by popular i18n libraries:
- Angular/ngx-translate:
{{ variable }} - React-i18next:
{{variable}} - Vue-i18n:
{variable} - Custom patterns:
%variable%,${variable},$variable$
Example translation file with placeholders:
{
"GREETINGS": {
"HELLO": "Hello {{name}}!",
"WELCOME": "Welcome back, {username}",
"GOOD_MORNING": "Good morning, ${user}!"
},
"MESSAGES": {
"ITEMS_COUNT": "You have {count} items in your cart",
"PRICE": "Total price: {{currency}}{{amount}}"
}
}See the examples/ folder for more configuration examples and sample translation files.
License
MIT TransLatté supports multiple translation sources - perfect for modular applications (Angular feature modules, React code-splitting, etc.)!
