xcstrings-translator is a powerful command-line tool specifically designed for translating Localizable.xcstrings files for iOS/macOS applications. This tool supports multiple translation service providers and boasts high-performance concurrent translation capabilities.
Read this in other languages: 中文
- Google Translate API: Supports neural machine translation models
- DeepL API: Provides high-quality translation, supporting both free and professional versions
- Baidu Translate API: Baidu Translate service
- OpenAI API: Supports translation capabilities of GPT series models
- Concurrency control based on Worker Pool mode
- Configurable number of concurrent requests
- Elegant error handling and retry mechanism
- Context timeout control
- Complete parsing and generation of xcstrings JSON format
- Intelligent detection of strings requiring translation
- Preserve original translations, translating only missing language versions
- Maintain file structure and metadata integrity
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ CLI Layer │ │ Service Layer │ │ Provider Layer │
│ (Cobra Commands)│────▶│ (Concurrency & │────▶│ (Translation │
│ │ │ Translation) │ │ Implementations)│
└─────────────────┘ └─────────────────┘ └─────────────────┘
▲ ▲ ▲
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ User Input │ │ Model Layer │ │ HTTP Client │
│ (Flags/Args) │ │ (Data Structures)│ │ (resty) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Concurrency is achieved using Goroutines and Channels
- Concurrency is controlled using the Worker Pool pattern
- Timeout control is implemented using the Context mechanism
- WaitGroup waits for all tasks to complete
- Go 1.21+: Main programming language
- Cobra: CLI framework
- resty: HTTP client
- JSON: xcstrings file format processing
- MD5: Baidu API signature generation
To install, run:
go install github.com/fdddf/xcstrings-translator@latest
Or download the binary from the releases page.
xcstrings-translator google \
--api-key "AIzaSy..." \
--input "Localizable.xcstrings" \
--output "Localizable_zh.xcstrings" \
--source-language "en" \
--target-languages "zh-Hans" "ja" \
--concurrency 10 \
--verbosexcstrings-translator deepl \
--api-key "2a7f4..." \
--free \
--input "Localizable.xcstrings" \
--output "Localizable_translated.xcstrings" \
--target-languages "zh-Hans"xcstrings-translator baidu \
--app-id "2024..." \
--app-secret "f4K..." --input "Localizable.xcstrings" --output "Localizable_baidu.xcstrings"
xcstrings-translator openai
--api-key "sk-proj..."
--model "gpt-4"
--input "Localizable.xcstrings" --output "Localizable_ai.xcstrings"
- API keys are passed via command-line arguments or environment variables
- No sensitive information is stored
- HTTPS encrypted transmission
- Input validation and error handling
- Connection pool reuse
- Batch request processing
- Intelligent retry mechanism
- Efficient memory management
- iOS/macOS application localization
- Batch translation of string resources
- CI/CD pipeline integration
- Multilingual application development
- Easy addition of new translation service providers
- Support for custom translation rules
- Integration into automated workflows
- Support for batch translation of large projects
- Translation caching mechanism
- Translation quality assessment
- Batch file processing
- Translation memory
- Interactive translation confirmation
🤝 Contribution Guidelines Contributions, problem reporting, and suggestions are welcome. The project uses a standard GitHub workflow:
- Fork the project
- Create a feature branch
- Submit changes
- Create a pull request