Cliente Weblate

Instalação

The Weblate Client is shipped separately and includes the Python module. To use the commands below, you need to install wlc using pip:

pip install wlc

You can also execute it directly using uvx:

uvx wlc --help

Dica

Também pode utilizar este wlc como um módulo Python, consulte wlc.

Uso do Docker

O Weblate Client também está disponível como uma imagem Docker.

A imagem está publicada no Docker Hub: https://hub.docker.com/r/weblate/wlc

Instalar:

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.

O comando para iniciar o contentor usa a seguinte sintaxe:

docker run --rm weblate/wlc [WLC_ARGS]

Exemplo:

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

You might want to pass your Ficheiros de configuração 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.

Primeiros Passos

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

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

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

Depois pode invocar comandos no servidor predefinido:

wlc ls
wlc commit sandbox/hello-world

Legacy configuration

Alterado na versão 1.17: The legacy configuration using unscoped key is no longer supported.

Migrate legacy configuration:

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

To a configuration with key scoped to an API URL:

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

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

Sinopse

wlc [arguments] <command> [options]

Os comandos indicam, na verdade, qual operação deve ser realizada.

Descrição

O cliente Weblate é uma biblioteca Python e utilitário de linha de comando para gerir o Weblate remotamente a usar a API REST do Weblate. O utilitário de linha de comando pode ser invocado como wlc e está embutido em wlc.

Argumentos

O programa aceita os seguintes argumentos que definem o formato de saída ou qual a instância do Weblate a utilizar. Estes devem ser inseridos antes de qualquer comando.

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

Especifica o formato de saída.

--url URL

Especifica a URL da API. Substitui qualquer valor encontrado no ficheiro de configuração, consulte Ficheiros de configuração. A URL deve terminar com /api/, por exemplo, https://hosted.weblate.org/api/.

--key KEY

Specify the API user key to use. Overrides any value found in the configuration file, see Ficheiros de configuração. 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 Ficheiros de configuração.

--config-section SECTION

Substitui a secção de ficheiros de configuração em uso, consulte Ficheiros de configuração.

Comandos

Os comandos seguintes estão disponíveis:

version

Imprime a versão atual.

list-languages

Lista os idiomas usados no Weblate.

list-projects

Lista os projetos no Weblate.

list-components

Lista os componentes no Weblate.

list-translations

Lista as traduções no Weblate.

show

Mostra o objeto do Weblate (tradução, componente ou projeto).

ls

Lista o objeto do Weblate (tradução, componente ou projeto).

commit

Faz um commit das alterações feitas num objeto Weblate (tradução, componente ou projeto).

pull

Faz um pull das alterações remotas do repositório no objeto Weblate (tradução, componente ou projeto).

push

Faz um push das alterações do objeto Weblate ao repositório remoto (tradução, componente ou projeto).

reset

Redefine as alterações no objeto Weblate para corresponder ao repositório remoto (tradução, componente ou projeto).

cleanup

Remove todas as alterações não rastreadas num objeto Weblate para corresponder ao repositório remoto (tradução, componente ou projeto).

repo

Exibe o estado do repositório para um determinado objeto do Weblate (tradução, componente ou projeto).

stats

Exibe estatísticas detalhadas para um determinado objeto Weblate (tradução, componente ou projeto).

lock-status

Exibe o estado do bloqueio.

lock

Bloqueia o componente de tradução posterior no Weblate.

unlock

Desbloqueia a tradução do componente Weblate.

changes

Exibe alterações para um determinado objeto.

download

Descarrega um ficheiro de tradução.

--convert

Converte o formato do ficheiro, se nenhuma conversão não especificada for feita no servidor e o ficheiro for descarregado como está no repositório.

--output

Especifica o ficheiro para gravar a saída e se não for especificado é impresso na stdout (saída predefinida).

upload

Descarrega um ficheiro de tradução.

--overwrite

Substitua as traduções existentes ao enviar.

--input

Ficheiro a partir do qual o conteúdo é lido, se não for especificado é lido de stdin (entrada predefinida).

--method

Método de envio para usar, veja Métodos de importação.

--fuzzy

Processamento de entradas imprecisas (marcadas para edição) (vazio, process, approve)

--author-name

Nome do autor, para substituir o utilizador atualmente autenticado

--author-email

Email do autor, para substituir o utilizador atualmente autenticado

Dica

Pode obter informações mais detalhadas sobre como invocar comandos individuais a passar --help, por exemplo: wlc ls --help.

Ficheiros de configuração

When --config is provided, wlc loads only that file.

Without --config, wlc first loads the discovered global configuration file from the standard platform-specific locations:

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

Global configuration file on Windows in the roamed profile.

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

Global configuration file on Windows in the local profile.

~/.config/weblate

Global configuration file on Unix-like systems.

/etc/xdg/weblate

System-wide fallback configuration file.

O programa segue a especificação XDG, para que possa ajustar o posicionamento de ficheiros de configuração por variáveis de ambiente XDG_CONFIG_HOME ou XDG_CONFIG_DIRS.

No Windows, os diretórios APPDATA e LOCALAPPDATA são os locais preferidos para o ficheiro de configuração.

After loading the global configuration, wlc loads the nearest project configuration file from the current directory or its parents:

.weblate, .weblate.ini, weblate.ini

Project configuration file placed in the repository.

Only the closest project configuration file is loaded. Configuration files in farther parent directories are ignored.

As configurações seguintes podem ser configuradas na secção [weblate] (pode personalizar-lo por --config-section):

key

Removed in version 1.17: Use the [keys] section to specify keys scoped for individual API URLs, see Legacy configuration.

url

URL de API do servidor, a predefinição é http://127.0.0.1:8000/api/.

translation

Caminho à tradução predefinida - componente ou projeto.

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.

O ficheiro de configuração é um ficheiro INI, por exemplo:

[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

The API keys are stored in the [keys] section:

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

Environment variables

Added in version 1.18.0.

Alterado na versão 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

URL da API

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. Command-line arguments (--url, --key).

  2. Environment variables (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.

Exemplos

Imprimir a versão atual do programa:

$ wlc version
version: 0.1

Listar todos os projetos:

$ 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/

Enviar ficheiro de tradução:

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

Também pode designar em qual projeto o wlc deve trabalhar:

$ 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/

Com esta configuração é fácil fazer um commit de alterações pendentes no projeto atual:

$ wlc commit