與 Weblate 集成

Weblate 基礎知識

Project and component structure

在 Weblate 中, 翻譯組織成為項目和組件。每個項目可以包含幾個組件,並且組件包含各個語言的翻譯。組件相應於一個翻譯文件(例如 GNU gettext安卓字符串資源)。項目幫助您將組件組織為邏輯的組(例如,將一個應用中使用的所有翻譯分組)。

默認情況下,每個項目內都有對跨組件傳播的公共字符串的翻譯。這減輕了重複和多版本翻譯的負擔。但假如翻譯應當有所不同,可以使用 允許翻譯再用 通過 組件配置 禁用翻譯傳播。

Importing localization project into Weblate

Weblate 在開發時一直注意將版本管理系統(VCS)作為核心功能。因此,最簡單的方法是授予 Weblate 訪問存儲庫的權限。導入過程將指導您將翻譯配置進組件。

可以替換使用 Weblate 來設置包含所有翻譯的本地倉庫而不合併。

Fetching updated translations from Weblate

為了從 Weblate 取回更新的字符串,可以簡單地取回基礎的Git倉庫(要么來自文件系統,要么可以通過 git-exporter`來獲得)。在這之前,您會想要提交任何掛起的更改(請參見 :ref:`lazy-commit)。這可以通過(在 Repository maintenance 中)或使用 Weblate 客戶端 從命令行來實現。

如果你向 Weblate 授予了對倉庫的推送訪問,並配置了 組件配置 中的 儲存庫推送 URL,此操作可以自動進行。見 推送 Weblate 的更改

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

Fetching remote changes into Weblate

To fetch the strings newly updated in your repository into Weblate, just let it pull from the upstream repository. This can be achieved in the user interface (in the Repository maintenance), or from the command-line using Weblate 客戶端.

這可以通過在你的存儲庫中設置一個 webhook 來自動實現,每當有新的提交時,webhook 就會觸發 Webate。更多細節請參見 更新倉庫

如果你沒在用一個版本管理系統(VCS)集成,可以使用 UI 或 Weblate 的 REST API 來更新翻譯,從而與您的碼基匹配。

Adding new strings

如您的翻譯文件與代碼一起存儲在一個版本控制系統(VCS)中,您很可能有一個現有的工作流供開發人員引入新的字符串。任何添加字符串的方法都將被採用,但請考慮使用 源字符串的質量網關 以避免引入錯誤。

當翻譯文件與代碼分離時,可以通過以下方法將新字符串引入 Weblate。

  • Manually, using Add new translation string from Tools menu in the source language.

  • Programmatically, using API POST /api/translations/(string:project)/(string:component)/(string:language)/units/.

  • 通過上傳源文件為:guilabel:Replace existing translation file`(這覆蓋了現有的字符串,因此請確定文件包括舊的和新的字符串)或:guilabel:`Add new strings,請參見: ref:upload-method

備註

在WebLate中添加字符串的可用性取決於:REF:“Component-Manage_Units`。

Updating target language files

For monolingual files (see 支持的文件格式) Weblate might add new translation strings not present in the 單語的基底語言檔, and not in actual translations. It does not however perform any automatic cleanup of stale strings as that might have unexpected outcomes. If you want to do this, please install 清理翻譯檔 add-on which will handle the cleanup according to your requirements.

Weblate also will not try to update bilingual files in any way, so if you need po files being updated from pot, you need to do it yourself using Update source strings 導入方法 or using 更新 PO 檔以符合 POT (msgmerge) add-on.

也參考

:參考:“處理”,:REF:“addon-webblate.cleanup.generic`,:ref:addon-webblate.cleanup.blank,:ref:addon-webblate.resx.update,:ref:addon-webblate.gettext.msgmerge

Managing version control repository

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

Following operations are available:

Commit

Commits any pending changes present in Weblate database and not in the repository, see 惰性提交.

Push

Pushes changes to the upstream repository, if configured by 儲存庫推送 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.