与 Weblate 集成

Weblate 基础知识

项目和组件架构

在 Weblate 中, 翻译组织成为项目和组件。每个项目可以包含几个组件,并且组件包含各个语言的翻译。组件相应于一个翻译文件(例如 GNU gettext安卓字符串资源)。项目帮助您将组件组织为逻辑的组(例如,将一个应用中使用的所有翻译分组)。

默认情况下,每个项目内都有对跨组件传播的公共字符串的翻译。这减轻了重复和多版本翻译的负担。但假如翻译应当有所不同,可以使用 允许同步翻译 通过 组件配置 禁用翻译传播。

正在将本地化项目导入 Weblate

Weblate 在开发时一直注意将版本管理系统(VCS)作为核心功能。因此,最简单的方法是授予 Weblate 访问存储库的权限。导入过程将指导您将翻译配置进组件。

可以替换使用 Weblate 来设置包含所有翻译的本地仓库而不合并。

正从 Weblate 获取更新的翻译

为了从 Weblate 取回更新的字符串,可以简单地取回基础的Git仓库(要么来自文件系统,要么可以通过 git-exporter`来获得)。在这之前,您会想要提交任何挂起的更改(请参见 :ref:`lazy-commit)。这可以通过(在 Repository maintenance 中)或使用 Weblate 客户端 从命令行来实现。

如果你向 Weblate 授予了对仓库的推送访问,并配置了 组件配置 中的 代码库推送 URL,此操作可以自动进行。见 推送 Weblate 的更改

或者,您可以使用 doc:/api 来更新翻译以匹配最新版本。

正获取远程更改到 Webate

为了将仓库中更新的字符串获取到 Weblate,只要从上游仓库拉取就可以了。这可以在用户界面(在 Repository maintenance 中)或使用 Weblate 客户端 从命令行来实现。

这可以通过在你的存储库中设置一个 webhook 来自动实现,每当有新的提交时,webhook 就会触发 Webate。更多细节请参见 更新仓库

如果你没在用一个版本管理系统(VCS)集成,可以使用 UI 或 Weblate 的 REST API 来更新翻译,从而与您的码基匹配。

正在添加新字符串

如您的翻译文件与代码一起存储在一个版本控制系统(VCS)中,您很可能有一个现有的工作流供开发人员引入新的字符串。任何添加字符串的方法都将被采用,但请考虑使用 Quality gateway for the source strings 以避免引入错误。

当翻译文件与代码分离时,可以通过以下方法将新字符串引入 Weblate。

注解

Availability of adding strings in Weblate depends on 管理字符串.

正在更新目标语言文件

对于单语言文件(请参见 支持的文件格式),Weblate 也许会添加不在 单语言译文模版语言文件 和实际翻译中的新翻译字符串。然而它不会对任何旧的字符串执行自动清理,因为那会具有难以预料的结果。如果想做的话,请安装附加组件 清理翻译文件 根据您的要求处理清理工作。

Weblate 也不会尝试以任何方式更新双语言文件,所以如果需要 po 文件从 pot 更新的话,需要您自己通过使用 Update source strings Import methods 或附加组件 :ref:`addon-weblate.gettext.msgmerge`来实现。

管理版本控制仓库

Weblate stores all translation the version control repository. It can be either connected to upstream one, or it can be only internal. The Repository maintenance lets you manipulate with the repository.

提示

With 持续本地化集成 the repository is automatically pushed whenever there are changes and there is usually no need to manually manipupate with it.

../_images/component-repository.png

下列操作可用:

Commit

提交任何在 Weblate 数据库中且不在代码库中的挂起更改,见 惰性提交

Push

如通过 :ref:`component-push`进行了配置,则将更改推送到上游代码库。

Update, Pull, Rebase

Updates Weblate repository with upstream changes. It uses 合并方式 when choosing Update or you can choose different one from the dropdown menu.

Lock

锁定防止译员进行更改

Reset from Maintenance

Resets any changes done in Weblate to match upstream repository. This will discard all translations done in Weblate and not present in the upstream repository.

Cleanup from Maintenance

Removes untracked files from the repository. These could be result of misbehaving add-ons or bugs.

Force synchronization from Maintenance

Forces writing all strings to the translation files. Use this when repository files became out of sync with Weblate for some reason.