Skip to content

About

Automate machine translations for your Weblate projects via CLI. Triggers batch automatic translations through the Weblate API, designed for scheduled/cron execution.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Weblate Automatic Translation

Python script to trigger batch automatic translations via Weblate API for configured projects and languages. Designed for daily cron execution.

Installation

# 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 settings

Configuration

Edit 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: INFO

Environment Variables

Set 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.

Usage

# 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

CLI Options

Option Description
--config PATH Config file location (default: config.yaml)
--dry-run Show actions without executing
--project SLUG Process only this project

Cron Setup

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>&1

Or 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.py

Filter Query Examples

The 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

Machine Translation Engines

Common engine identifiers (must be configured in Weblate):

  • deepl — DeepL
  • google-translate — Google Translate
  • microsoft-translator — Microsoft Translator
  • aws — Amazon Translate
  • libretranslate — LibreTranslate

Translation Mode

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.

Weblate Requirements

  1. API Token: User must have translation permissions
  2. MT Service: At least one machine translation engine configured
  3. Components: Target languages must be enabled per component

Troubleshooting

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

About

Automate machine translations for your Weblate projects via CLI. Triggers batch automatic translations through the Weblate API, designed for scheduled/cron execution.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages