管理指令

備註

不同使用者下執行管理指令而不是一人執行您的 web 伺服器,可以導致文件得到錯誤的權限,更多細節請查看 檔案系統權限

您會找到基本的管理指令(作為Django 來源中的 ./manage.py 來獲得它,或者作為可安裝在Weblate 頂層的指令碼呼叫 weblate 中的擴充組來獲得它)。

Invoking management commands

如上面所提到的,以用依賴於您如何安裝 Weblate。

如果使用 Python 環境執行 Weblate,您可以指定 weblate 的完整路徑,或在呼叫它之前先啟用該環境:

# Direct invocation
~/weblate-env/bin/weblate

# Activating Python environment adds it to search path
. ~/weblate-env/bin/activate
weblate

如果您直接使用原始碼(來源於 tarball 或 Git checkout ),管理指令稿可以在 Weblate 來源檔案的 ./manage.py 中獲得。要執行它:

python ./manage.py list_versions

如果你是使用 pip 安裝程式或 ./setup.py 安裝 Weblate,則 weblate 會被安裝到您的 PATH(或 Python 環境 PATH),你可以從那裡使用它來控制 Weblate:

weblate list_versions

對於 Docker 映像,指令碼向上面一樣安裝,您可以使用 docker exec 來執行:

docker exec --user weblate <container> weblate list_versions

對於 docker-compose-plugin,過程是相似的,您只是必須使用 docker compose exec

docker compose exec --user weblate weblate weblate list_versions

在您需要向它傳遞文件的情況下,您可以臨時新增儲存區:

docker compose exec --user weblate /tmp:/tmp weblate weblate importusers /tmp/users.json

add_suggestions

weblate add_suggestions <project> <component> <language> <file>

從文件匯入翻譯,來作為給定翻譯的建議來使用。它略過了複製翻譯的步驟;只會新增不同的內容。

--author USER@EXAMPLE.COM

E-mail of author for the suggestions. This user has to exist prior to importing (you can create one in the admin interface if needed).

範例:

weblate --author michal@cihar.com add_suggestions weblate application cs /tmp/suggestions-cs.po

auto_translate

weblate auto_translate <project> <component> <language>

在 4.6 版的變更: 新增了翻譯模式參數。

根據其他組件翻譯進行自動翻譯。

--source PROJECT/COMPONENT

Specifies the component to use as source available for translation. If not specified all components in the project are used.

--user USERNAME

Specify username listed as author of the translations. "Anonymous user" is used if not specified.

--overwrite

Whether to overwrite existing translations.

--inconsistent

Whether to overwrite existing translations that are inconsistent (see 不一致).

--add

Automatically add language if a given translation does not exist.

--mt MT

Use machine translation instead of other components as machine translations.

--threshold THRESHOLD

Similarity threshold for machine translation, defaults to 80.

--mode MODE

Specify translation mode, default is translate but fuzzy or suggest can be used.

範例:

weblate auto_translate --user nijel --inconsistent --source weblate/application weblate website cs

也參考

自動翻譯

backup

weblate backup

Runs configured backups synchronously, without using Celery. It first updates the settings and database backup dumps in DATA_DIR, then runs the selected Borg backup service or services.

--list

Lists configured backup service IDs.

--service ID

Runs one backup service by ID.

--all

Runs all enabled backup services.

Use Django's standard --verbosity 2 option to show backup service output. Failed backup service output is shown even without increased verbosity.

範例:

weblate backup --list
weblate backup --service 1 --verbosity 2
weblate backup --all

For Docker Compose deployments, you can stop the regular Weblate container and run the command in a one-off container using docker compose run. The database and configured backup storage still need to be available.

docker compose stop weblate
docker compose run --rm --user weblate weblate weblate backup --list
docker compose run --rm --user weblate weblate weblate backup --service 1 --verbosity 2

benchmark

weblate benchmark

Imports given content into Weblate, useful for benchmarking.

效能紀錄範例
# Run benchmark with a profiling
python -m cProfile -o benchmark.prof ./manage.py benchmark --project benchmark --filemask '*.tbx' --format tbx --zipfile /tmp/MicrosoftTermCollection2.zip

# Convert to SVG for visualization
uvx gprof2dot -f pstats benchmark.prof | dot -Tsvg -o benchmark.svg

# Display SVG
firefox ./benchmark.svg
記憶體紀錄範例
# Run benchmark under memray
uvx memray run ./manage.py benchmark --project benchmark --filemask '*.tbx' --format tbx --zipfile /tmp/MicrosoftTermCollection2.zip

# Render the profile
uvx memray flamegraph ./memray-manage.py.2554179.bin

# Display it
fixefox memray-flamegraph-manage.py.2554179.html

billing_demo

weblate billing_demo

在 5.15 版被加入.

Creates a demo billing project. Can be executed multiple times to add additional invoices and billing events.

這在開發 Weblate 時會有用。需要安裝 帳單

celery_queues

weblate celery_queues

顯示 Celery 工作佇列的長度。

也參考

背景工作內部

checkgit

weblate checkgit <project|project/component>

列印後端 Git 儲存庫的目前狀態。

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

commitgit

weblate commitgit <project|project/component>

將任何可能待定的變更提交給後端 Git 儲存庫。

You can either define which project or component to update (for example weblate/application), or use --all to update all existing components, or use --file-format to filter based on the file format.

commit_pending

weblate commit_pending <project|project/component>

提交早於給定時間段的待定變更。

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

--age HOURS

Age in hours for committing. If not specified the value configured in 組件配置 is used.

備註

這由 Weblate 在背景自動執行,所以實際不需要手動呼叫,除了要強制早於 組件配置 指定的執行。

cleanuptrans

weblate cleanuptrans

清理無主的檢查和翻譯建議。這通常不需要手動執行,因為清理在背景自動啟動。

也參考

執行維護事項

cleanup_memory

weblate cleanup_memory

在 5.13 版被加入.

Removes all obsolete entries with pending status from the translation memory.

cleanup_ssh_keys

weblate cleanup_ssh_keys

在 4.9.1 版被加入.

Performs cleanup of stored SSH host keys:

  • Removes deprecated RSA keys for GitHub which might cause issues connecting to GitHub.

  • Removes duplicate entries in host keys.

也參考

SSH 儲存庫

createadmin

weblate createadmin

除非指定,否則用隨機密碼建立 admin 帳號。

--password PASSWORD

Provides a password on the command-line, to not generate a random one.

--no-password

Do not set password, this can be useful with --update.

--username USERNAME

Use the given name instead of admin.

--email USER@EXAMPLE.COM

Specify the admin e-mail address.

--name

Specify the admin name (visible).

--update

Update the existing user (you can use this to change passwords).

dump_memory

weblate dump_memory

將包含 Weblate 翻譯記憶庫內容的 JSON 文件匯出。

dumpuserdata

weblate dumpuserdata <file.json>

透過 importuserdata 將 userdata 傾印至檔案供以後使用。

提示

這在遷移或合併 Weblate 事例是會很方便。

import_demo

weblate import_demo

在 4.1 版被加入.

依據 <https://github.com/WeblateOrg/demo> 建立一個 Demo 專案與組件。請確認 Celery 已先啟用在執行此指令前。

這在開發 Weblate 時會有用。

--delete

Removes existing demo project.

import_json

weblate import_json <json-file>

根據 JSON 資料批量匯入組件。

匯入的 JSON 檔案結構非常符合組件物件(請參閱 GET /api/components/(string:project)/(string:component)/ )。您必須包括 namefilemask 欄位。

--project PROJECT

Specifies where the components will be imported from.

--main-component COMPONENT

Use the given VCS repository from this component for all of them.

--ignore

Skip (already) imported components.

--update

Update (already) imported components.

JSON 檔案的範例:

[
  {
    "slug": "po",
    "name": "Gettext PO",
    "file_format": "po",
    "filemask": "po/*.po",
    "new_lang": "none"
  },
  {
    "name": "Android",
    "filemask": "android/values-*/strings.xml",
    "template": "android/values/strings.xml",
    "repo": "weblate://test/test",
    "file_format": "aresource"
  }
]

也參考

import_memory

import_memory

weblate import_memory <file>

將檔案匯入 Weblate 翻譯記憶庫。

Supported file formats are TMX, JSON, XLIFF, PO, CSV.

Specifying a source and a target languages might be necessary for formats other than JSON and TMX.

--language-map LANGMAP

Allows mapping languages in the TMX to the Weblate translation memory. The language codes are mapped after normalization usually done by Weblate.

--language-map en_US:en will for example import all en_US strings as en ones.

This can be useful in case your TMX file locales happen not to match what you use in Weblate.

--source-language SOURCE_LANG

Specifies the source language for imported translations. Typically needed for formats where the languages cannot be determined from the file itself.

--target-language TARGET_LANG

Specifies the target language for imported translations. Typically needed for formats where the languages cannot be determined from the file itself.

import_project

weblate import_project <project> <gitrepo> <branch> <filemask>

Batch imports components into project based on the file mask. It is based on the 組件探索 add-on, so you might want to use that instead.

<project> 將已存在的專案命名,組件將匯入其中。

<gitrepo> 確定了要使用的 Git 儲存庫的 URL,而 <branch> 說明了 Git 分支。為了從現有的 Weblate 組件匯入另外的翻譯組件,使用 <gitrepo>weblate://<project>/<component> URL。

<filemask> 為儲存庫定義了文件發現。或者可以使用萬用字元來使它簡單,或者可以使用正規表達式的全部功能。

簡單的匹配對組件名稱使用 **,對語言使用 *,例如: **/*.po

The regular expression has to contain groups named component and language, for example: (?P<language>[^/]*)/(?P<component>[^-/]*)\.po.

根據文件,匯入與現有的組件匹配,並且新增不存在的那些。它不變更已經存在的那些。

--name-template TEMPLATE

Customize the name of a component using Django template syntax.

For example: Documentation: {{ component }}

--base-file-template TEMPLATE

Customize the base file for monolingual translations.

For example: {{ component }}/res/values/string.xml

--new-base-template TEMPLATE

Customize the base file for addition of new translations.

For example: {{ component }}/ts/en.ts

--file-format FORMAT

You can also specify the file format to use (see 在地化檔案格式), the default is auto-detection.

--language-regex REGEX

You can specify language filtering (see 組件配置) with this parameter. It has to be a valid regular expression.

--main-component

You can specify which component will be chosen as the main one—the one actually containing the VCS repository.

--license NAME

Specify the overall, project or component translation license.

--license-url URL

Specify the URL where the translation license is to be found.

--vcs NAME

In case you need to specify which version control system to use, you can do it here. The default version control is Git.

為了給出一些範例,讓我們匯入兩個專案。

第一個是 Debian 手冊翻譯,那裡的每種語言都有各自的資料夾,裡面有 每個章節的翻譯:

weblate import_project \
    debian-handbook \
    https://salsa.debian.org/hertzog/debian-handbook.git \
    bullseye/main \
    '*/**.po'

Then the Tanaguru tool, where the file format needs be specified, along with the base file template, and how all components and translations are located in single folder:

weblate import_project \
    --file-format=properties \
    --base-file-template=web-app/tgol-web-app/src/main/resources/i18n/%s-I18N.properties \
    tanaguru \
    https://github.com/Tanaguru/Tanaguru \
    master \
    web-app/tgol-web-app/src/main/resources/i18n/**-I18N_*.properties

更複雜範例是關於解析文件名而從文件名中得到正確的組件和語言,像 src/security/Numerous_security_holes_in_0.10.1.de.po

weblate import_project \
    tails \
    git://git.tails.boum.org/tails master \
    'wiki/src/security/(?P<component>.*)\.(?P<language>[^.]*)\.po$'

篩選出指定的語言的翻譯:

./manage import_project \
    --language-regex '^(cs|sk)$' \
    weblate \
    https://github.com/WeblateOrg/weblate.git \
    'weblate/locale/*/LC_MESSAGES/**.po'

匯入 Sphinx 文件,分成多個文件:

$ weblate import_project --name-template 'Documentation: %s' \
    --file-format po \
    project https://github.com/project/docs.git master \
    'docs/locale/*/LC_MESSAGES/**.po'

匯入 Sphinx 文件,分成多個文件和資料夾:

$ weblate import_project --name-template 'Directory 1: %s' \
    --file-format po \
    project https://github.com/project/docs.git master \
    'docs/locale/*/LC_MESSAGES/dir1/**.po'
$ weblate import_project --name-template 'Directory 2: %s' \
    --file-format po \
    project https://github.com/project/docs.git master \
    'docs/locale/*/LC_MESSAGES/dir2/**.po'

也參考

More detailed examples can be found in the 通過國際化來開始 chapter, alternatively you might want to use import_json.

import_projectbackup

weblate import_projectbackup <project_name> <project_slug> <username> <filename>

在 5.10 版被加入.

匯入 專案層級備份

提示

Usually it is more comfortable to import project when 新增翻譯專案和組件.

importuserdata

weblate importuserdata <file.json>

Imports user data from a file created by dumpuserdata.

importusers

weblate importusers --check <file.json>

從 Django auth_users 資料庫的 JSON 傾印中匯入使用者。

--check

With this option it will just check whether a given file can be imported and report possible conflicts arising from usernames or e-mails.

You can dump users from the existing Django site using:

./manage.py dumpdata auth.User > users.json

提示

Use dumpuserdata for dumping data from other Weblate server as that includes user settings as well.

也參考

從 Pootle 遷移

install_addon

weblate install_addon --addon ADDON <project|project/component>

將附加元件安裝到一組元件中。

--addon ADDON

Name of the add-on to install. For example weblate.gettext.customize.

--configuration CONFIG

JSON encoded configuration of an add-on.

--update

Update the existing add-on configuration.

可以或者定義將附加元件安裝到哪個專案或元件中(例如 weblate/application),或者使用 --all 來包括所有現有的元件。

To install 產生 MO 檔案 for all components:

weblate install_addon --addon weblate.gettext.mo --configuration '{"fuzzy": true}' --update --all

也參考

附加元件

install_machinery

在 4.18 版被加入.

weblate install_machinery --service SERVICE

Installs an site-wide automatic suggestion service.

--service SERVICE

Name of the service to install. For example deepl.

--configuration CONFIG

JSON encoded configuration of a service.

--update

Update the existing service configuration.

To install DeepL:

weblate install_machinery --service deepl --configuration '{"key": "x", "url": "https://api.deepl.com/v2/"}' --update

也參考

自動建議

list_addons

weblate list_addons

Lists add-ons in reStructuredText as a template for 附加元件.

--sections {events,addons,parameters}

Filter the generated output to just the add-on event sections, the built-in add-on sections, or the shared add-on parameter sections. If omitted, all generated sections are shown.

list_permissions

weblate list_permissions

Lists permissions in reStructuredText as a template for 存取控制.

list_checks

weblate list_checks

Lists quality checks in reStructuredText as a template for 檢查和修復 and 檢查和修復.

--sections {checks,flags}

Filter the generated output to just the quality check sections or the shared check flag sections. If omitted, all generated sections are shown.

備註

Using --output requires selecting exactly one value in --sections so each generated snippet is written to its own file. This matches the 為 Weblate 說明文件作出貢獻 workflow and the make -C docs update-docs targets.

list_languages

weblate list_languages <locale>

列出 MediaWiki 標註中支援的語言——語言代碼、英語名稱和在地化名稱。

This is used to generate <https://www.l10n.cz/wiki/Slovn%C3%ADky/Slovn%C3%ADk_s_n%C3%A1zvy_jazyk%C5%AF/>.

list_machinery

weblate list_machinery

Lists automatic suggestions services in reStructuredText as a template for 自動建議.

list_translators

weblate list_translators <project|project/component>

對給定的專案列出為這種語言做出貢獻的翻譯者:

[French]
Jean Dupont <jean.dupont@example.com>
[English]
John Doe <jd@example.com>
--language-code

List names by language code instead of language name.

可以或者定義使用哪個專案或組件(例如 weblate/application),或者使用 --all 從所有現存的組件中列出翻譯者。

list_versions

weblate list_versions

列出所有 Weblate 依賴及其版本。

list_file_format_params

weblate list_file_format_params

列出檔案格式參數。

list_change_events

weblate list_change_events

Lists all possible change event types.

list_format_features

weblate list_format_features

Generates RST documentation snippets describing the supported features for every file format.

The command generates one file for every format, that can be found in the specified output directory.

--output PATH

Directory where the format feature snippets will be written.

備註

The generated documentation files are meant to be included in documentation sources such as 在地化檔案格式. See also weblate/formats/management/commands/list_format_features.py for customization and merging logic.

loadpo

weblate loadpo <project|project/component>

從磁碟重新載入翻譯(例如您在版本控制系統(VCS )儲存庫完成一些更新的情況下)。

--force

Force update, even if the files should be up-to-date.

--lang LANGUAGE

Limit processing to a single language.

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

備註

極少呼叫這個,Weblate 將對每一次版本控制系統(VCS )更新自動載入變更的文件。在您手動變更下層 Weblate 版本控制系統(VCS )儲存庫的情況下,或在更新後的一些特殊情況下才需要這個。

lock_translation

weblate lock_translation <project|project/component>

防止進一步翻譯組件。

提示

在您想要對下層儲存庫進行一些維護時有用。

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

也參考

unlock_translation

migrate

weblate migrate

Migrates database to current Weblate schema. The command line options are described at Django migrate.

提示

In case you want to run an installation non interactively, you can use weblate migrate --noinput, and then create an admin user using createadmin command.

move_language

weblate move_language source target

Allows you to merge language content. This is useful when updating to a new version which contains aliases for previously unknown languages that have been created with the (generated) suffix. It moves all content from the source language to the target one.

範例:

weblate move_language cze cs

After moving the content, you should check whether there is anything left (this is subject to race conditions when somebody updates the repository meanwhile) and remove the (generated) language.

pushgit

weblate pushgit <project|project/component>

將執行的變更推送到上游版本控制系統(VCS )儲存庫。

--force-commit

Force commits any pending changes, prior to pushing.

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

備註

如果開啟了 組件配置 中的 提交時一併推送,Weblate 會自動推送變更,這是預設的。

unlock_translation

weblate unlock_translation <project|project/component>

將給定的組件解鎖,使它能夠被翻譯。

提示

在您想要對下層儲存庫進行一些維護時有用。

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

也參考

lock_translation

setupgroups

weblate setupgroups

配置預設的組,並可選地將所有使用者指定到那個預設群組中。

--no-privs-update

Turns off automatic updating of existing groups (only adds new ones).

--no-projects-update

Prevents automatic updates of groups for existing projects. This allows adding newly added groups to existing projects, see 專案存取控制.

也參考

特權清單

setuplang

weblate setuplang

將 Weblate 中的確定語言的清單更新。

--no-update

Turns off automatic updates of existing languages (only adds new ones).

updatechecks

weblate updatechecks <project|project/component>

對所有字串更新所有檢查。

提示

對檢查進行主要變更的更新是有用的。

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

備註

Checks are recalculated regularly by Weblate in the background, the frequency can be configured via BACKGROUND_TASKS.

updategit

weblate updategit <project|project/component>

取回遠端版本控制系統(VCS )儲存庫並更新內部快取。

您可以確定或者哪個專案或組件要更新(例如 weblate/application ),或者使用 --all 來更新所有現有組件。

備註

Usually it is better to configure hooks in the repository to trigger 通知掛勾, instead of regular triggering the updates by updategit.