管理命令

备注

在与运行 web 服务器的用户不同的用户下运行管理命令,可能会导致文件获得错误的权限,请查阅 文件系统权限 了解详情。

您会找到基本的管理命令(作为 Django 源中的 ./manage.py 来获得它,或者作为可安装在Weblate 顶层的脚本调用 weblate 中的扩展组来获得它)。

调用管理命令

如上面所提到的,如何调用取决于您如何安装 Weblate。

如果使用 Python 环境来运行 Weblate,那么您可以指定 weblate 的完整路径,或者在调用前激活 Python 环境:

# 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 安装到您的路径下(或者 Python 环境路径下),您可以从那里用它控制 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

通过分析变更历史,估算贴近实际的人类译者日均处理量。该指令仅统计活跃人类用户的翻译单元(Translation Units)手动变更,并设置了每日处理量的上下限阈值,以过滤明显的离群值(Outliers)、Bot 脚本、批量导入、文件上传及其他干扰统计结果的异常事件。

--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 目录下的配置文件与数据库 Dump 备份文件,随后触发执行指定的 Borg 备份服务。

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

Added in version 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

Added in version 5.13.

从翻译记忆库删除所有未提交状态的废弃条目。

cleanup_ssh_keys

weblate cleanup_ssh_keys

Added in version 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 将 userdata 转储到文件供以后使用。

提示

这在迁移或合并 Weblate 实例时会很方便。

import_demo

weblate import_demo

Added in version 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)/)。您必须包括 name 和 filemask 字段。

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

正则表达式必须包含组命名的 component 和 language。例如:(?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'

然后 Tangaguru 工具,那里需要指定文件格式和翻译模板文件,并且指定所有部件和翻译如何位于单一一个文件夹中:

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>

Added in version 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 服务器转储数据,因为这也会包括用户设置。

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

Added in version 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_automation

weblate list_automation

Generates the automation reference from the workflow JSON Schema, including action names, parameters, and introduction versions. With --output, replaces generated blocks while preserving manual descriptions and cookbook examples outside those blocks.

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 来更新所有现有部件。

metrics

weblate metrics

输出 GET /api/metrics/ 暴露的服务器指标。

--format FORMAT

Selects the output format. Supported formats are json, csv, and openmetrics. The default is json.

migrate

weblate migrate

迁移数据库到当前 Weblate 方案。命令行选项描述见 Django migrate。

提示

在想要非交互式地运行安装的情况下,可以使用 weblate migrate --noinput,然后使用 createadmin 命令来建立管理用户。

move_language

weblate move_language source target

允许您合并语言内容。当更新到新版本,这个新版本对使用 (generated) 前缀建立的之前未知的语言包含别名时,这会有用。它将所有内容从 source 语言移动到 target 语言。

If both languages have a translation in the same component, or different workflow settings or font overrides for the same scope, the move is skipped without changing either language. Resolve the reported conflict before retrying. Identical workflow settings and font overrides are consolidated. Automatic language updates use the same checks and continue with other languages when a move is skipped.

示例:

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 会自动推送更改,这是默认的。

refresh_github_repositories

weblate refresh_github_repositories

Added in version 2026.10.1.

Refreshes the repository list of all connected GitHub accounts and retargets components whose repository was renamed or transferred on GitHub.

unlock_translation

weblate unlock_translation <project|project/component>

将给定的部件解锁,使它能够被翻译。

提示

在您想要对下层仓库进行一些维护时有用。

您可以确定或者哪个项目或部件要更新(例如 weblate/application),或者使用 --all 来更新所有现有部件。

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>

取回远程版本控制系统仓库并更新内部缓存。

您可以确定或者哪个项目或部件要更新(例如 weblate/application),或者使用 --all 来更新所有现有部件。

备注

通常最好在仓库中配置钩子,来触发 通知钩子,而不是定期通过 updategit 来触发更新。