與 Weblate 整合

Weblate 基礎知識

專案和元件結構

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

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

Repository integration

Weblate is built to integrate with upstream version control repository, 持續在地化 describes building blocks and how the changes flow between them.

也參考

Architecture overview describes how Weblate works internally.

User attribution

Weblate keeps the translations properly authored by translators in the version control repository by using name and e-mail. Having a real e-mail attached to the commit follows the distributed version control spirits and allows services like GitHub to associate your contributions done in Weblate with your GitHub profile.

This feature also brings in risk of misusing e-mail published in the version control commits. Moreover, once such a commit is published on public hosting (such as GitHub), there is effectively no way to redact it. Weblate allows choosing a private commit e-mail in 帳號 to avoid this.

Therefore, admins should consider this while configuring Weblate:

  • Such a usage of e-mail should be clearly described in service terms in case such document is needed. 法律 can help with that.

  • PRIVATE_COMMIT_EMAIL_OPT_IN can make e-mails private by default.

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

If your translation files are stored in a remote VCS together with the code, you most likely have an existing workflow for developers to introduce new strings. Any way of adding strings will be picked up, but consider using 來源字串的品質閘道 to avoid introducing errors.

When translation files are separated from the code, the following ways can introduce new strings into Weblate.

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

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

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

備註

The ability to add strings in Weblate requires 管理字串.

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 (like xgettext or intltool-update). 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.

提示

Automating string extraction is presently out of scope for Weblate. It typically involves executing untrusted code what makes it more suitable for a generic continuous integration than localization-specific platform.

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