與 Weblate 整合#

Weblate 基礎知識#

專案和元件結構#

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

預設情況下,每個專案內都有對跨元件傳播的公共字串的翻譯。這減輕了重複和多版本翻譯的負擔。但假如翻譯應當有所不同,可以使用 允許翻譯再用 通過 :ref:`component`停用翻譯傳播。

Importing localization project into Weblate#

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

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

Fetching updated translations from Weblate#

Weblate stores updated strings in a database and commits them to a local version control repository. You can add Weblate repository (when Git 導出器 is turned on) as additional remote and fetch translations update from it.

Prior to this, you might want to commit any pending changes (see 簡易提交). You can do so in the user interface (in the Repository maintenance) or from the command-line using Weblate 客戶端.

Pushing changes can be automated if you grant Weblate push access to your repository and configure 儲存庫推送 URL in the 組件組態, see 推送 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。

備註

在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:“處理”,:ref:“addon-webblate.cleanup.generic`,addon-webblate.cleanup.blankaddon-webblate.resx.updateaddon-webblate.gettext.msgmerge

Introducing new strings#

You can add new strings in Weblate with 管理字串 turned on, but it is usually better to introduce new strings together with the code changes that introduced them.

Monolingual formats need addition of the new string to 單語的基底語言檔. This is typically done by the developers during developing the code. You might want to introduce review of those strings using 來源字串的品質閘道.

Bilingual formats typically extract strings from the source code using some tooling. Follow your localization framework documentation for instructions how to do that. Once the strings are extracted, there might be an additional step needed to update existing translations, see Updating target language files.

提示

You might want to integrate this into your continuous integration pipelines to make new strings automatically appear for translation. Such pipeline should also cover 避免發生合併衝突.

管理版本控制倉儲#

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