@jynsama/auto-translate
v1.1.1
Published
Automatically translate JSON and PHP locale files using OpenAI GPT
Maintainers
Readme
auto-translate
Automatically translate your i18n JSON and PHP files using OpenAI's GPT.
Installation
npm install -g auto-translateUsage
auto-translate <path-to-locales-folder> [options]Options
-h, --help # Display help message
-b, --batch-size <number> # Set translation batch size (default: 5)
-e, --exclude <directories> # Directories to exclude (comma-separated, default: vendor)Examples
# Basic usage
auto-translate ./locales
# Exclude multiple directories
auto-translate ./locales --exclude vendor,cache,temp
# Custom batch size and exclusions
auto-translate ./locales -b 10 -e vendor,node_modulesRequirements
- Node.js
- Git repository
- OpenAI API Key
Environment Variables
Before using auto-translate, you need to set your OpenAI API key:
export AT_OPENAI_API_KEY="your-openai-api-key"Folder Structure
The script expects your locales folder to follow this structure:
your-i18n-folder/ ├── en/ # Source language (English) │ ├── file1.json # JSON files │ ├── file2.php # PHP files │ └── subfolder/ │ └── file3.json ├── fr/ # Target language (French) │ ├── file1.json │ ├── file2.php │ └── subfolder/ │ └── file3.json └── it/ # Target language (Italian) ├── file1.json ├── file2.php └── subfolder/ └── file3.json ...
Supported File Formats
JSON files (
.json)PHP files (
.php) with the following structure:<?php return [ 'key' => 'value', 'nested' => [ 'key' => 'value' ] ];
Excluding Directories
By default, the vendor directory is excluded. You can exclude additional directories using the -e or --exclude option:
# Exclude vendor and node_modules
auto-translate ./locales -e vendor,node_modules
# Exclude multiple directories
auto-translate ./locales --exclude vendor,cache,temp,node_modulesHow it Works
- Detects changes in your English (en) source files using Git
- Only translates new or modified content
- Preserves existing translations for unchanged content
- Maintains file structure and formatting
- Supports nested JSON objects and arrays
- Handles both JSON and PHP translation files
