管理指令

備註

Running management commands under a different user than the one running your webserver can result in files getting wrong permissions, please check 檔案系統權限 for more details.

You will find basic management commands (available as ./manage.py in the Django sources, or as an extended set in a script called weblate installable atop Weblate).

呼叫管理指令

As mentioned before, invocation depends on how you installed Weblate.

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

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

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

If you are using source code directly (either from a tarball or Git checkout), the management script is ./manage.py available in the Weblate sources. To run it:

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>

Imports a translation from the file to use as a suggestion for the given translation. It skips duplicated translations; only different ones are added.

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

匯入給定內容至 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 版被加入.

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

This can be useful when developing Weblate. Needs 帳單 installed.

celery_queues

weblate celery_queues

顯示 Celery 工作佇列長度。

也參考

背景工作內部

checkgit

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

commitgit

weblate commitgit <project|project/component>

Commits any possible pending changes to the back-end Git repository.

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>

Commits pending changes older than a given age.

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

--age HOURS

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

備註

This is automatically performed in the background by Weblate, so there no real need to invoke this manually, besides forcing an earlier commit than specified by 組件配置.

cleanuptrans

weblate cleanuptrans

Cleans up orphaned checks and translation suggestions. There is normally no need to run this manually, as the cleanups happen automatically in the background.

也參考

執行維護事項

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.

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

也參考

SSH 儲存庫

createadmin

weblate createadmin

Creates an admin account with a random password, unless it is specified.

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

Dumps userdata to a file for later use by importuserdata.

提示

這在遷移或合併 Weblate 實例時非常有用。

import_demo

weblate import_demo

在 4.1 版被加入.

Creates a demo project with components based on <https://github.com/WeblateOrg/demo>. Make sure the celery tasks are running before running this command.

這在開發 Weblate 時可能很有用。

--delete

Removes existing demo project.

import_json

weblate import_json <json-file>

基於 JSON 資料批次匯入組件。

The imported JSON file structure pretty much corresponds to the component object (see GET /api/components/(string:project)/(string:component)/). You have to include the name and filemask fields.

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

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> names an existing project, into which the components are to be imported.

The <gitrepo> defines the Git repository URL to use, and <branch> signifies the Git branch. To import additional translation components from an existing Weblate component, use a weblate://<project>/<component> URL for the <gitrepo>.

The <filemask> defines file discovery for the repository. It can be either be made simple using wildcards, or it can use the full power of regular expressions.

The simple matching uses ** for component name and * for language, for example: **/*.po

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

The import matches existing components based on files and adds the ones that do not exist. It does not change already existing ones.

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

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

First The Debian Handbook translations, where each language has separate a folder with the translations of each chapter:

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

More complex example of parsing of filenames to get the correct component and language out of a filename like 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'

Importing Sphinx documentation split to multiple files:

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

Importing Sphinx documentation split to multiple files and directories:

$ 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 Starting with internationalization 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>

Imports users from JSON dump of the Django auth_users database.

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

You can either define which project or component to install the add-on in (for example weblate/application), or use --all to include all existing components.

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.

要安裝 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>

Lists supported languages in MediaWiki markup - language codes, English names and localized names.

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

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

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>

Reloads translations from disk (for example in case you have done some updates in the VCS repository).

--force

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

--lang LANGUAGE

Limit processing to a single language.

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

備註

You seldom need to invoke this, Weblate will automatically load changed files for every VCS update. This is needed in case you manually changed an underlying Weblate VCS repository or in some special cases following an upgrade.

lock_translation

weblate lock_translation <project|project/component>

Prevents further translation of a component.

提示

Useful in case you want to do some maintenance on the underlying repository.

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

也參考

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>

Pushes committed changes to the upstream VCS repository.

--force-commit

Force commits any pending changes, prior to pushing.

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

備註

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

unlock_translation

weblate unlock_translation <project|project/component>

Unlocks a given component, making it available for translation.

提示

Useful in case you want to do some maintenance on the underlying repository.

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

也參考

lock_translation

setupgroups

weblate setupgroups

Configures default groups and optionally assigns all users to that default group.

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

Updates list of defined languages in Weblate.

--no-update

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

updatechecks

weblate updatechecks <project|project/component>

Updates all checks for all strings.

提示

Useful for upgrades which do major changes to checks.

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

備註

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

updategit

weblate updategit <project|project/component>

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

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

備註

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