@pulimoodan/localiser
v1.0.3
Published
AI-powered internationalization tool that automatically translates JSON locale files using OpenAI's GPT-4 model
Downloads
25
Maintainers
Readme
Localiser
An AI-powered internationalization tool that automatically translates JSON locale files using OpenAI's GPT-4 model. Localiser supports batch translation across multiple languages and namespaces with a simple CLI interface.
Features
- 🤖 AI-Powered Translation: Uses OpenAI's GPT-4 for high-quality translations
- 📁 Namespace Management: Organize translations by namespaces (e.g., home, settings, common)
- 📊 Real-time Progress: Visual progress bars showing translation status
- ⚡ CLI Interface: Simple command-line interface for easy integration
- 🔧 Configurable: Flexible configuration through JSON files
To Do
- 🗂️ Dynamic folder structure support: Now supports lang/namespace.json, lang.json is not supported yet
- 💿 Optimized translation: Translate only missing keys in the target language files (add a flag to override existing translations)
- 🤖 AI Model selection: Allow users to choose between different OpenAI models (e.g., GPT-3.5, GPT-4)
- 🎬 Init command: Add a command to initialize the project with default configuration json file
Feel free to contribute to the project by submitting issues or pull requests!
Installation
Prerequisites
- Node.js (v16 or higher)
- OpenAI API key (Add this to
.envfile of your project)
Install Globally
npm install -g @pulimoodan/localiserConfiguration
Environment Variables
Create a .env file in your project root:
OPENAI_API_KEY=your_openai_api_key_hereProject Configuration
Create a localiser.json file to configure your translation settings:
{
"directory": "public/locales",
"sourceLanguage": "en",
"languages": ["fr", "es", "de", "it", "pt", "zh", "ja", "ru"],
"namespaces": ["home", "settings"]
}Configuration Options
directory: Path to your locales directorysourceLanguage: Source language code (e.g., "en")languages: Array of target language codes to translate tonamespaces: Array of namespace names to translate
Usage
Basic Usage
Translate all configured languages and namespaces:
loaliserTranslate Specific Language
loaliser --language fr,esTranslate Specific Namespaces
loaliser --namespace home,settingsTranslate Specific Language and Namespace
loaliser --language fr --namespace homeCustom Configuration File
localiser --config custom-config.jsonCLI Options
| Option | Short | Description | Default |
| ------------- | ----- | -------------------------------- | ------------------------- |
| --language | -l | Target languages code | All configured languages |
| --namespace | -n | Specific namespaces to translate | All configured namespaces |
| --config | -c | Path to configuration file | localiser.json |
Dependencies
commander: CLI argument parsingdotenv: Environment variable managementfs-extra: Enhanced file system operationsopenai: OpenAI API client
License
ISC License
Author
pulimoodan
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues and questions, please open an issue on the GitHub repository.
