管理指令

備註

在與執行 web 伺服器的使用者不同的使用者下執行管理指令,可能會導致檔案獲得錯誤的權限,請查閱 檔案系統權限 瞭解詳情。

您會看到基本管理指令:Django 原始碼中的 ./manage.py,或安裝於 Weblate 上層、名為 weblate 的指令碼所提供的擴充指令集。

呼叫管理指令

如上面所提到的,如何呼叫取決於您如何安裝 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

analyze_translator_work

weblate analyze_translator_work

分析變更歷程,以估算符合實際情況的翻譯者每日處理量。此指令只納入活躍的人類使用者和以翻譯單元為依據的手動翻譯變更,並套用每日最低和最高門檻,以排除明顯的離群值、機器人、批次匯入、上傳,以及其他會干擾結果的事件。

--days DAYS

Number of recent days to analyze when --since is not specified.

--since YYYY-MM-DD

Start date for the analysis.

--until YYYY-MM-DD

End date for the analysis.

--project PROJECT

Limit the analysis to a project slug.

--component PROJECT/COMPONENT

Limit the analysis to a component.

--language LANGUAGE

Limit the analysis to a language code.

--min-changes COUNT

Minimum translated strings per user day to include.

--max-changes COUNT

Maximum translated strings per user day to include.

--max-words COUNT

Maximum translated source words per user day to include.

範例:

weblate analyze_translator_work --project weblate --since 2026-01-01

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

同步執行已設定的備份,不使用 Celery。此指令會先更新 DATA_DIR 中的設定和資料庫備份傾印,再執行選取的 Borg 備份服務。

--list

Lists configured backup service IDs.

--service ID

Runs one backup service by ID.

--all

Runs all enabled backup services.

使用 Django 標準的 --verbosity 2 選項顯示備份服務輸出。即使未提高詳細程度,也會顯示執行失敗的備份服務輸出。

範例:

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

對於 Docker Compose 部署,可以停止一般 Weblate 容器,並使用 docker compose run 在一次性容器中執行指令。資料庫及已設定的備份儲存空間仍必須可用。

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

匯入給定內容至 Weblate 中,對基準測試有用。

效能分析範例
# 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 版被加入.

建立演示帳單專案。可多次執行新增額外的發票和帳單事件。

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

celery_queues

weblate celery_queues

顯示 Celery 工作佇列長度。

也參考

背景工作內部

checkgit

weblate checkgit <project|project/component>

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

您可以指定要更新的專案或元件(例如 weblate/application),或使用 --all 更新所有既有元件。

commitgit

weblate commitgit <project|project/component>

將任何可能的待處理變更提交到後端 Git 儲存庫。

您可以指定要更新的專案或元件(例如 weblate/application)、使用 --all 更新所有既有元件,或使用 --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 版被加入.

從翻譯記憶移除所有狀態為待處理的過時項目。

cleanup_ssh_keys

weblate cleanup_ssh_keys

在 4.9.1 版被加入.

對儲存的 SSH 主機金鑰進行清理:

  • 移除已廢棄的 GitHub 的 RSA 金鑰,這可能會導致連線到 GitHub 的問題。

  • 移除主機金鑰中的重複條目。

也參考

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 使用。

提示

這在移轉或合併 Weblate 執行個體時非常有用。

import_demo

weblate import_demo

在 4.1 版被加入.

基於 <https://github.com/WeblateOrg/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 翻譯記憶。

支援的檔案格式有 TMX 、 JSON 、 XLIFF 、 PO 、 CSV。

指定來源與目標語言對於 JSON 與 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>

基於檔案掩碼批次匯入元件到專案中。它基於 元件探索 附加元件,您或許想使用該附加元件。

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

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

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

簡單的相符對元件名稱使用 **,對語言使用 *,例如:**/*.po

正規表示式必須包含組命名的 componentlanguage。例如:(?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'

接著是 Tanaguru 工具:除了基礎檔案範本,還必須指定檔案格式,以及所有元件和翻譯如何放在同一個資料夾中:

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'

也參考

更多具體的範例可以在 從國際化開始 章節找到,另外您會想要使用 import_json

import_projectbackup

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

在 5.10 版被加入.

匯入 專案層級備份

提示

通常 新增翻譯專案和元件 時匯入專案更輕鬆。

importuserdata

weblate importuserdata <file.json>

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.

可以用下列方法從現有 Django 網站轉儲使用者:

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

提示

dumpuserdata 從其他 Weblate 伺服器轉儲資料,因為這也會包括使用者設定。

也參考

從 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 來包含所有現有的元件。

為所有元件安裝 產生 MO 檔案

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

也參考

附加元件

install_machinery

在 4.18 版被加入.

weblate install_machinery --service 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.

要安裝 DeepL

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

也參考

自動建議

list_addons

weblate list_addons

將 reStructuredText 中的附加元件作為 附加元件 的範本列出。

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

將 reStructuredText 中的權限作為 存取控制 的範本列出。

list_checks

weblate list_checks

將 reStructuredText 中的品質檢查作為 檢查與修復檢查與修復 的範本列出。

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

備註

使用 --output 要求在 --sections 中只選一個值,這樣每個產生的文字片段都寫入自己的檔案中。這相符 為 Weblate 說明文件作出貢獻 工作流以及 make -C docs update-docs 目標。

list_languages

weblate list_languages <locale>

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

這用來產生 <https://www.l10n.cz/wiki/Slovn%C3%ADky/Slovn%C3%ADk_s_n%C3%A1zvy_jazyk%C5%AF/>。

list_machinery

weblate list_machinery

將 reStructuredText 中的自動建議服務作為 自動建議 的範本列出。

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

列出所有可能的變更事件類型。

list_format_features

weblate list_format_features

產生描述每個檔案格式受支援功能的 RST 檔案片段。

此指令為每個格式產生一個檔案,可以在指定的輸出目錄中找到此檔案。

--output PATH

Directory where the format feature snippets will be written.

備註

所產生的檔案檔案用於包含在 在地化檔案格式 等檔案源中。另見 weblate/formats/management/commands/list_format_features.py 取得自訂和合並邏輯的資訊。

loadpo

weblate loadpo <project|project/component>

從磁碟重新載入翻譯(例如,您在版本控制系統儲存庫中進行了一些更新)。

--force

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

--lang LANGUAGE

Limit processing to a single language.

您可以指定要更新的專案或元件(例如 weblate/application),或使用 --all 更新所有既有元件。

備註

您很少需要呼叫這個指令,Weblate 會在每次版本控制系統更新時自動載入變更的檔案。如果您手動變更了 Weblate 的底層版本控制系統儲存庫,或者在升級後的某些特殊情況下,則需要呼叫這個指令。

lock_translation

weblate lock_translation <project|project/component>

防止元件的進一步翻譯。

提示

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

您可以指定要更新的專案或元件(例如 weblate/application),或使用 --all 更新所有既有元件。

也參考

unlock_translation

migrate

weblate migrate

移轉資料庫到目前 Weblate 方案。指令列選項描述見 Django migrate

提示

在想要非互動式地執行安裝的情況下,可以使用 weblate migrate --noinput,然後使用 createadmin 指令來建立管理使用者。

move_language

weblate move_language source target

允許合併語言內容。升級至新版時,如果新版為先前以 (generated) 後置字串建立的未知語言加入別名,這項功能會很有用。它會將所有內容從 source 語言移至 target 語言。

範例:

weblate move_language cze cs

移動內容後,您應該檢查是否有什麼落下了(這是因為有人在同時更新儲存庫而導致的競爭情況),並且要刪除 (generated) 語言。

pushgit

weblate pushgit <project|project/component>

將提交的變更推送到上游的版本控制系統儲存庫。

--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 更新所有既有元件。

備註

檢查由 Weblate 定期在後臺重新計算,可以使用 BACKGROUND_TASKS 設定頻率。

updategit

weblate updategit <project|project/component>

取得遠端 VCS 儲存庫並更新內部快取。

您可以指定要更新的專案或元件(例如 weblate/application),或使用 --all 更新所有既有元件。

備註

通常最好在儲存庫中設定掛勾,來觸發 通知掛勾,而不是定期透過 updategit 來觸發更新。