Weblate Client

Installation

Weblate Client wird separat ausgeliefert und enthält das Python-Modul. Um die folgenden Befehle zu verwenden, müssen Sie wlc mit pip installieren:

pip install wlc

Sie können ihn auch direkt mit uvx ausführen:

uvx wlc --help

Hinweis

Sie können auch dieses wlc als ein Python-Modul verwenden, siehe wlc.

Docker-Nutzung

Weblate Client ist auch als Docker-Image verfügbar.

Das Image ist auf Docker Hub veröffentlicht: https://hub.docker.com/r/weblate/wlc

Installieren:

docker pull weblate/wlc

The Docker container uses Weblate Client defaults and connects to the API deployed on localhost. Configure the API URL and API key using the normal wlc arguments or environment variables, for example --url, --key, WLC_URL, and WLC_KEY. API keys are rejected over non-local http:// URLs by default; use HTTPS, loopback HTTP for local development, or explicitly opt in to insecure HTTP.

Der Befehl zum Starten des Containers hat die folgende Syntax:

docker run --rm weblate/wlc [WLC_ARGS]

Beispiel:

docker run --rm weblate/wlc --url https://hosted.weblate.org/api/ list-projects

You might want to pass your Konfigurationsdateien to the Docker container. When your repository contains a project configuration such as .weblate, the easiest approach is to add your current directory as the /home/weblate volume:

docker run --volume $PWD:/home/weblate --rm weblate/wlc show

When the mounted repository provides the API URL in project configuration and you pass an unscoped API key to the container, also pin the URL explicitly: WLC_KEY requires WLC_URL, and --key requires --url.

If the configured API URL uses non-local http:// and an API key is provided, the container refuses to send the key unless insecure HTTP is explicitly enabled. Prefer HTTPS; for legacy deployments, pass --allow-insecure-http or set WLC_ALLOW_INSECURE_HTTP.

Erste Schritte

The easiest way to get started is to create a personal wlc configuration in ~/.config/weblate (see Konfigurationsdateien for the full discovery rules and other locations):

[weblate]
url = https://hosted.weblate.org/api/

[keys]
https://hosted.weblate.org/api/ = APIKEY

Sie können dann Befehle auf dem Standardserver aufrufen:

wlc ls
wlc commit sandbox/hello-world

Ältere Konfiguration

Geändert in Version 1.17: Die alte Konfiguration mit uneingeschränktem key wird nicht mehr unterstützt.

Migrieren Sie Ihre alte Konfiguration:

[weblate]
url = https://hosted.weblate.org/api/
key = YOUR_KEY_HERE

Zu einer Konfiguration mit Schlüssel, die auf eine API-URL beschränkt ist:

[weblate]
url = https://hosted.weblate.org/api/

[keys]
https://hosted.weblate.org/api/ = YOUR_KEY_HERE

Kurzfassung

wlc [arguments] <command> [options]

Die Befehle geben an, welcher Vorgang ausgeführt werden soll.

Beschreibung

Weblate Client ist eine Python-Bibliothek und ein Befehlszeilenprogramm zur Fernverwaltung von Weblate über Weblates REST-API. Das Befehlszeilenprogramm kann als wlc aufgerufen werden und ist in wlc integriert.

Argumente

Das Programm akzeptiert die folgenden Argumente, die das Ausgabeformat oder die zu verwendende Weblate-Instanz definieren. Diese müssen vor jedem Befehl eingegeben werden.

--format {csv,json,text,html}

Gibt das Ausgabeformat an.

--url URL

Gibt die API-URL an. Überschreibt jeden Wert, der in der Konfigurationsdatei gefunden wird, siehe Konfigurationsdateien. Die URL sollte mit /api/ enden, zum Beispiel https://hosted.weblate.org/api/.

--key KEY

Specify the API user key to use. Overrides any value found in the configuration file, see Konfigurationsdateien. You can find your key in your profile on Weblate. When the API URL is loaded from automatically discovered project configuration, --key must be used together with --url. API keys are rejected over non-local http:// URLs by default.

--allow-insecure-http

Allow sending API keys over non-local http:// URLs. Prefer HTTPS or loopback HTTP instead; this option is intended only for legacy deployments where HTTPS is not available. This option only enables insecure HTTP for the current run; omitting it does not disable allow_insecure_http from configuration.

--config PATH

Load configuration only from PATH instead of the discovered global and project configuration files, see Konfigurationsdateien.

--config-section SECTION

Überschreibt den Abschnitt der verwendeten Konfigurationsdatei, siehe Konfigurationsdateien.

Befehle

Die folgenden Befehle sind verfügbar:

version

Gibt die aktuelle Version aus.

list-languages

Listet die in Weblate verwendeten Sprachen auf.

list-projects

Listet die Projekte in Weblate auf.

list-components

Listet die Komponenten in Weblate auf.

list-translations

Listet die Übersetzungen in Weblate auf.

show

Zeigt das Weblate-Objekt an (Übersetzung, Komponente oder Projekt).

ls

Listet das Weblate-Objekt auf (Übersetzung, Komponente oder Projekt).

commit

Committet Änderungen am Weblate-Objekt (Übersetzung, Komponente oder Projekt).

pull

Zieht Änderungen aus einem Remote-Repository in ein Weblate-Objekt (Übersetzung, Komponente oder Projekt).

push

Pusht Änderungen an Weblate-Objekten in ein Remote-Repository (Übersetzung, Komponente oder Projekt).

reset

Setzt Änderungen im Weblate-Objekt zurück, damit es mit dem Remote-Repository übereinstimmt (Übersetzung, Komponente oder Projekt).

cleanup

Entfernt alle nicht nachverfolgten Änderungen im Weblate-Objekt, um es an das Remote-Repository anzupassen (Übersetzung, Komponente oder Projekt).

repo

Zeigt den Repository-Status für ein bestimmtes Weblate-Objekt an (Übersetzung, Komponente oder Projekt).

stats

Zeigt detaillierte Statistiken für ein bestimmtes Weblate-Objekt an (Übersetzung, Komponente oder Projekt).

lock-status

Zeigt den Sperrstatus an.

lock

Sperrt die Komponente vor weiterer Übersetzung in Weblate.

unlock

Entsperrt die Übersetzung der Weblate-Komponente.

changes

Zeigt Änderungen für ein bestimmtes Objekt an.

download

Lädt eine Übersetzungsdatei herunter.

--convert

Wandelt das Dateiformat um, wenn nicht angegeben, erfolgt keine Umwandlung auf dem Server und die Datei wird unverändert in das Repository heruntergeladen.

--output

Gibt die Datei an, in der die Ausgabe gespeichert werden soll; wenn sie nicht angegeben wird, wird sie auf stdout ausgegeben.

upload

Lädt eine Übersetzungsdatei hoch.

--overwrite

Überschreibt vorhandene Übersetzungen beim Hochladen.

--input

Datei, aus welcher der Inhalt gelesen wird; wenn nicht angegeben, wird er von stdin gelesen.

--method

Zu verwendende Upload-Methode, siehe Importmethoden.

--fuzzy

Verarbeitung von ungenauen (zur Bearbeitung markierte) Zeichenketten (leer, process, approve)

--author-name

Autor-Name, um den aktuell authentifizierten Benutzer zu überschreiben

--author-email

Autor-E-Mail, um den aktuell authentifizierten Benutzer zu überschreiben

Hinweis

Genauere Informationen zum Aufruf einzelner Befehle erhalten Sie, wenn Sie --help übergeben, zum Beispiel: wlc ls --help.

Konfigurationsdateien

Wenn --config angegeben wird, lädt wlc nur diese Datei.

Ohne --config, lädt wlc zunächst die erkannte globale Konfigurationsdatei aus den standardmäßigen plattformspezifischen Orten:

C:\Users\NAME\AppData\Roaming\weblate.ini

Globale Konfigurationsdatei unter Windows im Roaming-Profil.

C:\Users\NAME\AppData\Local\weblate.ini

Globale Konfigurationsdatei unter Windows im lokalen Profil.

~/.config/weblate

Globale Konfigurationsdatei auf Unix-ähnlichen Systemen.

/etc/xdg/weblate

Systemweite Fallback-Konfigurationsdatei.

Das Programm folgt der XDG-Spezifikation, so dass Sie die Platzierung der Konfigurationsdateien durch die Umgebungsvariablen XDG_CONFIG_HOME oder XDG_CONFIG_DIRS anpassen können.

Unter Windows sind die Verzeichnisse APPDATA und LOCALAPPDATA die bevorzugten Orte für die Konfigurationsdatei.

Nach dem Laden der globalen Konfiguration lädt wlc die nächstgelegene Projekt-Konfigurationsdatei aus dem aktuellen Verzeichnis oder dessen übergeordneten Verzeichnissen:

.weblate, .weblate.ini, weblate.ini

Projekt-Konfigurationsdatei, die im Repository abgelegt wird.

Es wird nur die nächstgelegene Projekt-Konfigurationsdatei geladen. Konfigurationsdateien in weiter entfernten übergeordneten Verzeichnissen werden ignoriert.

Die folgenden Einstellungen können im Abschnitt [weblate] konfiguriert werden (Sie können dies mit --config-section anpassen):

key

Removed in version 1.17: Verwenden Sie den Abschnitt [keys] zur Angabe von Schlüsseln, die für einzelne API-URLs gelten, siehe Ältere Konfiguration.

url

API-Server-URL, standardmäßig http://127.0.0.1:8000/api/.

translation

Pfad zur Standardübersetzung – Komponente oder Projekt.

allow_insecure_http

Allow API keys over non-local http:// URLs, defaults to false. Loopback HTTP URLs, such as http://127.0.0.1:8000/api/, remain allowed for local development without this option. Prefer HTTPS instead of enabling this setting. Automatically discovered project configuration files cannot enable this option; set it in user configuration, an explicit --config file, WLC_ALLOW_INSECURE_HTTP, or --allow-insecure-http. The setting is cumulative: any trusted source that enables insecure HTTP is enough, and false or unset values from command-line or environment sources do not disable it.

retries, timeout, allowed_methods, backoff_factor, status_forcelist

Optional HTTP retry and timeout settings passed to urllib3. Use allowed_methods to list the request methods that may be retried. Current wlc releases use this setting name in place of the older method_whitelist option.

Die Konfigurationsdatei ist eine INI-Datei, zum Beispiel:

[weblate]
url = https://hosted.weblate.org/api/
translation = weblate/application
retries = 3
allowed_methods = PUT,POST,GET
backoff_factor = 0.2
status_forcelist = 429,500,502,503,504
timeout = 30
allow_insecure_http = false

Die API-Schlüssel werden im Abschnitt [keys] gespeichert:

[keys]
https://hosted.weblate.org/api/ = APIKEY

This allows you to store keys in your personal settings, while using the .weblate configuration in the VCS repository so that wlc knows which server it should talk to. The [keys] lookup is scoped to the exact API URL.

In CI, unscoped keys must pin the API URL explicitly: set both WLC_URL and WLC_KEY, or use --url together with --key.

Umgebungsvariablen

Added in version 1.18.0.

Geändert in Version 2.0.1: Unscoped API keys require an explicit API URL when project configuration is discovered automatically. API keys are rejected over non-local http:// URLs unless insecure HTTP is explicitly enabled.

The API URL and key can also be configured using environment variables. This is especially useful for CI workflows where WLC_URL pins the destination and WLC_KEY is injected as a secret:

WLC_URL

API-URL

WLC_KEY

API key. When the API URL would otherwise come from automatically discovered project configuration, WLC_KEY is accepted only together with WLC_URL. API keys are rejected over non-local http:// URLs by default.

WLC_ALLOW_INSECURE_HTTP

Set to 1, true, yes, or on to allow API keys over non-local http:// URLs. Prefer HTTPS or loopback HTTP instead. Other values, such as 0 or false, are treated as unset and do not disable allow_insecure_http from configuration.

The same protection applies to command-line arguments: --key is accepted with automatically discovered project configuration only when --url is provided.

The API URL and key configuration precedence (highest to lowest) is:

  1. Befehlszeilenargumente (--url, --key).

  2. Umgebungsvariablen (WLC_URL, WLC_KEY).

  3. Configuration loaded from --config, or from the discovered global configuration plus the nearest project configuration when --config is not used.

The insecure HTTP opt-in is enable-only rather than a normal precedence setting. It is enabled when --allow-insecure-http is passed, when WLC_ALLOW_INSECURE_HTTP has a true value, or when allow_insecure_http is enabled in trusted configuration. Automatically discovered project configuration cannot enable it; set it in user configuration or pass an explicit --config file instead.

Beispiele

Aktuelle Programmversion ausgeben:

$ wlc version
version: 0.1

Alle Projekte auflisten:

$ wlc list-projects
name: Hello
slug: hello
url: http://example.com/api/projects/hello/
web: https://weblate.org/
web_url: http://example.com/projects/hello/

Übersetzungsdatei hochladen:

$ wlc upload project/component/language --input /tmp/hello.po

Es ist auch möglich anzugeben, an welchem Projekt wlc arbeiten soll:

$ cat .weblate
[weblate]
url = https://hosted.weblate.org/api/
translation = weblate/application

$ wlc show
branch: main
file_format: po
source_language: en
filemask: weblate/locale/*/LC_MESSAGES/django.po
git_export: https://hosted.weblate.org/git/weblate/application/
license: GPL-3.0+
license_url: https://spdx.org/licenses/GPL-3.0+
name: Application
new_base: weblate/locale/django.pot
project: weblate
repo: git://github.com/WeblateOrg/weblate.git
slug: application
template:
url: https://hosted.weblate.org/api/components/weblate/application/
vcs: git
web_url: https://hosted.weblate.org/projects/weblate/application/

Mit dieser Einrichtung können ausstehende Änderungen im aktuellen Projekt einfach committet werden:

$ wlc commit