与 Weblate 集成

Weblate 基础知识

项目和部件架构

在 Weblate 中,翻译被组织成项目和部件。每个项目可以包含多个部件,这些部件又包含各个语言的翻译。部件对应的是一个可翻译的文件(例如 GNU gettextAndroid 字符串资源)。项目可以帮助您将部件组织成逻辑集合(例如,将一个应用中用到的所有翻译集合在一起)。

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

将本地化项目导入 Weblate

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

或者,您可以使用 Weblate 设置一个包含所有翻译的本地存储库,无需集成。

从 Weblate 获取更新的翻译

要从 Weblate 获取更新的字符串,只需获取底层的 Git 仓库(要么来自文件系统,要么可以通过 Git 导出器 获取)。在这之前,您可能想要先提交任何待处理的更改(请参见 惰性提交)。这可以通过在用户界面(在 Repository maintenance)或使用 Weblate 客户端 从命令行执行此操作。

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

另外,您还可以使用 Weblate 的 REST API 来更新翻译以匹配最新版本。

将远程更改获取到 Weblate

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

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

如果你没在用一个版本管理系统(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 导入方式更新 PO 文件以匹配 POT 文件 (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 manipulate with it.

../_images/component-repository.png

下列操作可用:

Commit

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

Push

如通过 代码库推送 URL 进行了配置,则将更改推送到上游代码库。

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.