Python script to trigger batch automatic translations via Weblate API for configured projects and languages. Designed for daily cron execution.
# Create virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Configure
cp config.yaml.example config.yaml
# Edit config.yaml with your settingsEdit config.yaml:
weblate:
url: "https://your-weblate.example.com"
api_token: "${WEBLATE_API_TOKEN}" # Uses environment variable
projects:
- my-project-1
- my-project-2
languages:
- fr
- de
- es
machine_translation:
engines: ["deepl"]
threshold: "80"
filter:
query: "state:<translated"
logging:
level: INFOSet the API token as an environment variable:
export WEBLATE_API_TOKEN="your-api-token-here"Get your API token from Weblate: User Settings → API access → Personal API key.
# Test with dry-run (shows actions without executing)
python weblate_autotranslate.py --dry-run
# Run for all configured projects
python weblate_autotranslate.py
# Run for a single project
python weblate_autotranslate.py --project my-project-1
# Use custom config location
python weblate_autotranslate.py --config /path/to/config.yaml| Option | Description |
|---|---|
--config PATH |
Config file location (default: config.yaml) |
--dry-run |
Show actions without executing |
--project SLUG |
Process only this project |
Run daily at 3 AM:
# Edit crontab
crontab -e
# Add entry
0 3 * * * WEBLATE_API_TOKEN="your-token" /path/to/venv/bin/python /path/to/weblate_autotranslate.py --config /path/to/config.yaml >> /var/log/weblate-autotranslate.log 2>&1Or use a wrapper script:
#!/bin/bash
# /usr/local/bin/weblate-autotranslate.sh
export WEBLATE_API_TOKEN="your-token"
cd /path/to/weblate_automatic_translation
/path/to/venv/bin/python weblate_autotranslate.pyThe filter.query setting uses Weblate's search syntax:
| Query | Description |
|---|---|
state:<translated |
Untranslated and unfinished strings |
state:empty |
Only empty translations |
state:fuzzy |
Only fuzzy/needs editing strings |
NOT state:translated |
All non-translated strings |
state:empty AND priority:>=100 |
Empty strings with high priority |
Common engine identifiers (must be configured in Weblate):
deepl— DeepLgoogle-translate— Google Translatemicrosoft-translator— Microsoft Translatoraws— Amazon Translatelibretranslate— LibreTranslate
The machine_translation.mode setting controls how translations are saved:
| Mode | Description |
|---|---|
fuzzy |
Mark as "Needs editing" (default) — requires human review |
translate |
Save as fully translated/approved |
suggest |
Add as suggestion only — doesn't modify string |
Default is fuzzy to ensure human review of machine translations.
- API Token: User must have translation permissions
- MT Service: At least one machine translation engine configured
- Components: Target languages must be enabled per component
401 Unauthorized: Check API token is valid and exported
404 Not Found: Verify project/component slugs exist
No translations triggered: Check if target languages are enabled in components
Rate limiting: Add delays between API calls if needed (modify script)
Enable debug logging for detailed output:
logging:
level: DEBUG