xlf-auto-translator
is a Python script designed to simplify and automate the translation of .xlf
files. It identifies untranslated strings in the XML content and translates them using an AI-based translation engine. The script supports OpenAI's API and is compatible with other translation engines.
- Automated Translation: Quickly translate untranslated strings in
.xlf
files. - AI-Powered: Compatible with OpenAI and other translation engines.
- Customizable: Easily adapt the script to work with your preferred translation service.
- Standards-Compliant: Works seamlessly with
.xlf
files adhering to the XLIFF standard.
- Python 3.7 or higher
- An API key for the translation engine of your choice (e.g., OpenAI's API)
-
Clone the repository:
git clone https://github.com/erseco/xlf-auto-translator.git cd xlf-auto-translator
-
Install the required dependencies:
pip install -r requirements.txt
-
Set up your API key: Create a
.env
file in the project directory and add your API key:OPENAI_API_KEY=your_api_key_here OPENAI_API_URL=https://api.openai.com/v1
The script provides several options for translating XLF files:
python translate.py <input-file.xlf> [options]
--language
,-l
: Target language (e.g., es, fr, de). If not provided, will try to detect from filename--inline
,-i
: Edit file in-place instead of creating a new file--force
,-f
: Force translation of all strings, even if already translated
Basic usage (creates a new translated file):
python translate.py messages.es.xlf
Specify target language explicitly:
python translate.py messages.xlf --language es
Edit file in-place:
python translate.py messages.es.xlf --inline
Force retranslation of all strings:
python translate.py messages.es.xlf --force
Configure the OpenAI API settings in your .env
file:
OPENAI_API_KEY=your_openai_api_key
OPENAI_API_URL=https://api.openai.com/v1
- Automatic language detection from filename
- Preserves XML structure and formatting
- Maintains CDATA sections and HTML entities
- Batch processing to optimize API usage
- Progress bar for translation status
- Statistics about translated/untranslated strings
- Interactive confirmation before translation
- Add support for additional translation engines.
- Implement batch processing for multiple
.xlf
files. - Provide detailed logs for the translation process.
- Include a fallback mechanism for untranslated strings.
Contributions are welcome! Feel free to submit issues, feature requests, or pull requests.
This project is licensed under the MIT License. See the LICENSE
file for details.
For questions or suggestions, feel free to contact us or open an issue in the repository.