crossfire-i18n
v1.0.0
Published
AI-powered JSON i18n translation tool with CrossFire Translation - use multiple source languages for higher accuracy
Downloads
5
Maintainers
Readme
CrossFire i18n
A CLI tool for automatically translating JSON-based i18n files using AI, featuring CrossFire Translation - a revolutionary approach that uses multiple source languages simultaneously for higher translation accuracy.
✨ Key Features
🎯 CrossFire Translation
Use multiple source languages simultaneously to achieve unprecedented translation accuracy. By cross-referencing translations from different languages, AI can better understand context, cultural nuances, and technical terminology.
Traditional Translation:
English → AI → JapaneseCrossFire Translation:
English + Chinese → AI → Japanese (Higher accuracy!)🚀 Other Features
- ✅ Batch translation with progress bars
- ✅ Smart incremental updates (only translate changed content)
- ✅ Support for OpenAI API and compatible services (Qwen/DashScope)
- ✅ Proxy support
- ✅ Nested JSON structure support
- ✅ Translation status tracking
📦 Installation
npm install -g crossfire-i18nOr use locally in your project:
npm install --save-dev crossfire-i18n🔧 Configuration
1. User Configuration (~/.i18n-update.json)
Create a global configuration file with your API credentials:
For OpenAI:
{
"openaiApiKey": "sk-xxx",
"openaiUrl": "https://api.openai.com/v1",
"openaiModel": "gpt-3.5-turbo-1106"
}For Alibaba Cloud DashScope (Qwen):
{
"openaiApiKey": "sk-xxx",
"openaiUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"openaiModel": "qwen-turbo"
}Available Qwen Models:
qwen-turbo- Fast and cost-effectiveqwen-plus- Better performanceqwen-max- Best quality
2. Project Configuration (i18n-update.config.js)
Create a configuration file in your project root:
Standard Mode (Single Source Language)
export default {
sourcePath: 'src/i18n', // Path to i18n files
sourceLocale: 'en', // Source language
locales: ['zh', 'ja', 'es'] // Target languages
}🔥 CrossFire Mode (Multiple Source Languages)
export default {
sourcePath: 'src/i18n',
sourceLocale: ['en', 'zh'], // Multiple source languages!
locales: ['ja', 'es', 'fr']
}🎮 Usage
Navigate to your project directory and run:
crossfire-i18nStandard Mode Output:
Translating... zh
████████████████████████████████████████ 100% | 20/20
Translating... ja
████████████████████████████████████████ 100% | 20/20CrossFire Mode Output:
Translating... ja (CrossFire mode)
████████████████████████████████████████ 100% | 20/20
Translating... es (CrossFire mode)
████████████████████████████████████████ 100% | 20/20📂 Project Structure
your-project/
├── i18n-update.config.js # Project configuration
├── i18n-update.status.json # Translation status (auto-generated)
└── src/i18n/
├── en.json # Source language
├── zh.json # Generated translation
├── ja.json # Generated translation
└── ...💡 CrossFire Translation Examples
Example 1: Technical Terms
When translating to Japanese:
- English: "Session timeout"
- Chinese: "会话超时"
- Result: AI understands it's about user sessions, not general timeout
Example 2: Cultural Nuances
When translating to Spanish:
- English: "Welcome back!"
- Chinese: "欢迎回来!"
- Result: Captures both formal greeting and friendly exclamation
Example 3: Ambiguous Words
When translating "Profile":
- English: "Profile" (could mean user profile, company profile, etc.)
- Chinese: "用户资料" (clearly indicates user profile)
- Result: Eliminates ambiguity for accurate translation
🎯 When to Use CrossFire Translation
Use CrossFire Translation when:
- ✅ You need maximum translation accuracy
- ✅ Your content has technical terminology
- ✅ Context and cultural nuances are important
- ✅ You already have high-quality translations in multiple languages
- ✅ You're translating between languages with different linguistic structures
📝 Supported i18n Formats
CrossFire i18n works with any JSON-based i18n format. Your JSON files should follow this structure:
{
"app": {
"title": "Welcome to Our Application",
"subtitle": "The best way to manage your tasks"
},
"user": {
"login": "Login",
"logout": "Logout",
"profile": "User Profile"
},
"action": {
"save": "Save",
"cancel": "Cancel",
"delete": "Delete"
}
}The tool will:
- Flatten the nested structure (e.g.,
app.title,user.login) - Translate each value
- Reconstruct the nested structure in target language files
Compatible with:
- Vue i18n
- React i18next
- Angular i18n
- Any framework using JSON-based i18n files
🔄 Incremental Translation
CrossFire i18n intelligently tracks translation status:
- First run: Translates all content
- Subsequent runs: Only translates new or changed content
- Status tracking: Stores in
i18n-update.status.json
Example status tracking:
{
"app.title": {
"value": "Welcome to Our Application",
"locales": {
"zh": true,
"ja": true,
"es": true
}
}
}🌐 Proxy Support
Set the https_proxy environment variable for proxy support:
export https_proxy=http://your-proxy:port
crossfire-i18n🧪 Examples
Check out the example projects:
test-case/- Standard single-source translationtest-case-crossfire/- CrossFire multi-source translation
📋 Configuration Options
Project Config (i18n-update.config.js)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| sourcePath | string | 'src/i18n' | Path to i18n files |
| sourceLocale | string | string[] | 'en' | Source language(s) |
| locales | string[] | [] | Target languages |
User Config (~/.i18n-update.json)
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| openaiApiKey | string | Yes | API key for OpenAI or compatible service |
| openaiUrl | string | No | Custom API endpoint |
| openaiModel | string | No | Model name (default: gpt-3.5-turbo-1106) |
🚀 Advanced Usage
Custom API Endpoint
If you're using a self-hosted or alternative OpenAI-compatible API:
{
"openaiApiKey": "your-key",
"openaiUrl": "https://your-api.example.com/v1",
"openaiModel": "your-model-name"
}Environment Variables
# Use proxy
export https_proxy=http://proxy:8080
# Run translation
crossfire-i18n🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
MIT
🎉 Why CrossFire i18n?
Traditional translation tools use a single source language, which can lead to:
- ❌ Ambiguous translations
- ❌ Lost cultural context
- ❌ Incorrect technical terminology
CrossFire i18n solves these problems by:
- ✅ Cross-referencing multiple source languages
- ✅ Leveraging AI's multilingual understanding
- ✅ Providing context-aware, accurate translations
- ✅ Maintaining consistency across all languages
Made with ❤️ for the global development community
