與 Weblate 整合¶
Weblate 基礎知識¶
專案和元件結構¶
在 Weblate 中, 翻譯組織成為項目和組件。每個項目可以包含幾個組件,並且組件包含各個語言的翻譯。組件相應於一個翻譯文件(例如 GNU gettext PO (Portable Object) 或 Android 字串資源)。項目幫助您將組件組織為邏輯的組(例如,將一個應用中使用的所有翻譯分組)。
Additionally, components within projects can be structured using categories. Components can belong to a category, and categories can be nested.
預設情況下,每個專案內都有對跨元件傳播的公共字串的翻譯。這減輕了重複和多版本翻譯的負擔。但假如翻譯應當有所不同,可以使用 允許翻譯再用 通過 :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 a localization project into Weblate¶
Weblate has been developed with VCS integration in mind as it’s core feature, so the easiest way is to grant Weblate the access to your repository. The import process will guide you through configuring your translations into Weblate components.
Alternatively, you can let Weblate set up a local-only repository containing all the translations without integration.
Fetching updated translations from Weblate¶
Weblate stores updated strings in a database and commits them to a local version-control repository. You can add a Weblate repository (when Git 導出器 is turned on) as an additional remote repository and fetch translation updates from it.
Prior to this, you might want to commit any pending local changes made in Weblate (see 簡易送交). This can be done from 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 的更改.
Alternatively, use Weblate 的 REST API to update translations so that they match the latest version from the upstream in your remote VCS repository.
也參考
取得遠端變更至 Weblate¶
To fetch any strings recently updated in your remote VCS repository into Weblate, allow Weblate to pull from the upstream repository. This can be achieved in the user interface (in the Repository maintenance), or from the command-line using Weblate 客戶端.
This can be automated by setting a webhook in your repository to trigger Weblate whenever there is a new commit. See 更新儲存庫 for more details.
If not using VCS integration, you can use the UI or Weblate 的 REST API to update the translations so that they match your codebase.
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. You can choose between the radio buttons Singular and Plural inside the form. Select the appropriate form of the new translation string to be added.
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 present in the 單語的基底語言檔, and not in actual translations. It does not however perform any automatic cleanup of stale strings, as that might have unexpected results. If you still want to do this, please install the 清理翻譯檔 add-on, which handles cleanup according to your requirements.
Weblate will also not try to update bilingual files when the source changes,
so if you need po
files to be updated from pot
, do it yourself by
using Update source strings 導入方法, or by using
the 更新 PO 檔以符合 POT (msgmerge) add-on.
提示
Source string extraction tools, such as xgettext or lupdate, need to be executed outside of Weblate.
也參考
:ref:“處理”,:ref:“addon-webblate.cleanup.generic`,addon-webblate.cleanup.blank,addon-webblate.resx.update,addon-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 to be configured so that new strings are added to 單語的基底語言檔. This is typically done by developers, as they write the code. You might want to use a review process 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 避免發生合併衝突.
Managing the local VCS repository¶
Weblate stores all translations in its underlying version control repository. It is suggested to be connected to a remote one, but internal-only setup is also possible. The Repository maintenance allows controlling this repository.
提示
With 持續在地化, any changes are automatically pushed from the repository, so there is usually no need to manually manage it manually.