持續在地化#

有適當的基礎結構,因此您的翻譯緊隨開發。這樣,翻譯人員可以一直進行翻譯,而不必在發佈之前處理大量的新文本。

也參考

與 Weblate 整合 描述了將您的開發整合到 Weblate 中的基本方式。

這是過程:

  1. 開發人員進行更改並將其推送到版本控制系統(VCS )儲存庫。

  2. Optionally the translation files are updated, see Introducing new strings.

  3. Weblate 從版本控制系統(VCS )儲存庫中拉取變更,請參見 更新儲存庫

  4. 一旦 Weblate 檢測到翻譯更改,便會根據翻譯者的訂閱設定通知他們。

  5. 翻譯者使用 Weblate Web 界面提交翻譯,或上傳離線更改。

  6. 翻譯者完成後,Weblate 會將變更提交到本機儲存庫(請參見 簡易提交),如果有權限將其推送回來(請參見 推送 Weblate 的更改)。

digraph translations { graph [fontname = "sans-serif", fontsize=10]; node [fontname = "sans-serif", fontsize=10, margin=0.1, height=0]; edge [fontname = "sans-serif", fontsize=10]; "Developers" [shape=box, fillcolor="#144d3f", fontcolor=white, style=filled]; "Translators" [shape=box, fillcolor="#144d3f", fontcolor=white, style=filled]; "Developers" -> "VCS repository" [label=" 1. Push "]; "VCS repository" -> "VCS repository" [label=" 2. Updating translations ", style=dotted]; "VCS repository" -> "Weblate" [label=" 3. Pull "]; "Weblate" -> "Translators" [label=" 4. Notification "]; "Translators" -> "Weblate" [label=" 5. Translate "]; "Weblate" -> "VCS repository" [label=" 6. Push "]; }

更新儲存庫#

應該新建一些從他們的來源來更新後端儲存庫的方式。

每當 Weblate 更新儲存庫時,更新後外掛都將被觸發,請參見 附加元件

避免發生合併衝突#

當相同的文件在 Weblate 之內與之外都更改時導致 Weblate 的合併衝突。有兩種方法來處理——避免在 Weblate 之外編輯,或者將 Weblate 整合到您的更新過程中,從而在更新 weblate 之外的文件之前刷新更改。

第一種方法容易用於單語言檔案——可以新增 Weblate 之內的新字串,並將檔案的整個編輯留在那裡。對於雙語言檔案,通常存在某種訊息提取過程而從來源碼產生翻譯檔。在一些情況下,這可以分成兩部分——一部分用於提取過程產生模板(例如使用 xgettext 產生 gettext POT ),然後下一步過程將它合併到真正的翻譯中(例如使用 :program :msgmerge 更新 gettext PO 檔案)。可以在 Weblate 中執行第二步,它將確認在這個操作前所有待定的變更都包括進去了。

第二種方法可以這樣實現,使用 Weblate 的 REST API,當您在自己一側進行更改時,強制 Weblate 推送所有待定的更改,並鎖定翻譯。

進行更新的腳本看起來像這樣:

# Lock Weblate translation
wlc lock
# Push changes from Weblate to upstream repository
wlc push
# Pull changes from upstream repository to your local copy
git pull
# Update translation files, this example is for Django
./manage.py makemessages --keep-pot -a
git commit -m 'Locale updates' -- locale
# Push changes to upstream repository
git push
# Tell Weblate to pull changes (not needed if Weblate follows your repo
# automatically)
wlc pull
# Unlock translations
wlc unlock

如果多個組件分享相同的儲存庫,需要分別將他們全部鎖定:

wlc lock foo/bar
wlc lock foo/baz
wlc lock foo/baj

備註

例子使用了 Weblate 客戶端,這需要組態 (API 金鑰)來遠端控制 Weblate。可以通過使用 HTTP 客戶端代替 wlc,例如 curl 來實現,請參見 Weblate 的 REST API

也參考

Weblate 客戶端

從 GitHub 自動接收更改#

Weblate 伴隨 GitHub 本地支援。

如果使用 Hosted Weblate,推薦的方法是安裝 Weblate app,該方法能夠得到正確的設定,而不必設定很多東西。它還可以用於將更改推送回來。

為了在每次推送到 GitHub 儲存庫時接收通知,將 Weblate Webhook 新增到儲存庫設定( Webhooks )中,如下圖所示:

../_images/github-settings.png

對於負載 URL,將 /hooks/github/ 增補到您的 Weblate URL中,例如對於 Hosted Weblate 服務,這是 https://hosted.weblate.org/hooks/github/

可以將其他設定保留為預設值( Weblate 可以處理內容類型,並只消費 push 事件)。

從 Bitbucket 自動接收更改#

Weblate 已經支援 Bitbucket webhooks,新增儲存庫推送時觸發的 webhook,目的地為您的 Weblate 安裝上的``/hooks/bitbucket/`` (例如``https://hosted.weblate.org/hooks/bitbucket/ `` )。

../_images/bitbucket-settings.png

從 GitLab 自動接收更改#

Weblate 已經支援GitLab hooks,新增項目的webhook,目的地為您的Weblate 安裝上的``/hooks/gitlab/`` (例如``https://hosted.weblate.org/hooks/gitlab/`` )。

從 Pagure 自動接受更改#

Weblate 已經支援Pagure hooks,新增項目的webhook,目的地為您的Weblate 安裝上的``/hooks/pagure/`` (例如``https://hosted.weblate.org/hooks/pagure/`` )。這可以在 Project options 之下的 Activate Web-hooks 中完成:

../_images/pagure-webhook.png

從 Azure Repos 自動接收更改#

Weblate 已經支援Azure Repos web hooks,為:guilabel:Code pushed 事件新增webhook,目的地為您的Weblate 安裝上的``/hooks/azure/`` URL (例如``https://hosted.weblate .org/hooks/azure/`` )。這可以在 Project settings 之下的 Service hooks 中完成。

從 Gitea Repos 自動接收更改#

Weblate 已經支援Gitea webhooks,為:guilabel:Push events 事件新增:guilabel:Gitea Webhook,目的地為您的Weblate 安裝上的``/hooks/gitea/`` URL (例如``https:/ /hosted.weblate.org/hooks/gitea/`` )。這可以在 Settings 之下的 Webhooks 中完成。

從 Gitee Repos 自動接收更改#

Weblate 已經支援Gitee webhooks,為:guilabel:Push 事件新增:guilabel:Webhook,目的地為您的Weblate 安裝上的``/hooks/gitee/`` URL (例如``https://hosted .weblate.org/hooks/gitee/`` )。這可以在 Management 之下的 Webhooks 中完成。

每晚自動更新儲存庫#

Weblate 在後面合併變更時,每晚自動擷取遠端儲存庫來提高效能。可以選擇將其同樣轉換為進行每晚合併,通過允許 AUTO_UPDATE

推送 Weblate 的更改#

每個翻譯組件可以新建推送 URL(請參見 儲存庫推送 URL ),在那種情況下 Weblate 能夠將更改推送到遠端倉儲。 Weblate 還可以組態在每次提交時自動推送更改(這是預設的,請參見 提交時一併推送 )。如果不想更改自動給推送,可以在 Repository maintenance 之下手動進行,或通過 wlc push 使用 API。

推送選項根據使用的 版本控制整合 而不同,更多細節可以在那個章節中找到。

In case you do not want direct pushes by Weblate, there is support for GitHub pull requests, GitLab 合併請求, Gitea pull requests, Pagure 合併請求 pull requests or Gerrit reviews, you can activate these by choosing GitHub, GitLab, Gitea, Gerrit or Pagure as 版本控制系統 in 組件組態.

整體上, Git 、 GitHub 和 GitLab 可以具有後面的選項:

需要的設定

版本控制系統

儲存庫推送 URL

推送分支

不推送

Git

直接推送

Git

SSH URL

Push to separate branch

Git

SSH URL

分支名稱

不推送

Mercurial

直接推送

Mercurial

SSH URL

Push to separate branch

Mercurial

SSH URL

分支名稱

來自叉子的 GitHub 拉取請求

GitHub pull requests

來自分支的 GitHub 拉取請求

GitHub pull requests

SSH URL [1]

分支名稱

來自叉子的 GitLab 結合請求

GitLab 合併請求

來自分支的 GitLab 結合請求

GitLab 合併請求

SSH URL [1]

分支名稱

Gitea merge request from fork

Gitea pull requests

Gitea merge request from branch

Gitea pull requests

SSH URL [1]

分支名稱

來自分叉的Pargue合併請求

Pagure 合併請求

來自分支的 Pagure合併請求

Pagure 合併請求

SSH URL [1]

分支名稱

備註

還可以允許 Weblate 提交後更改的自動推送,這可以在 提交時一併推送 中完成。

也參考

請參見 存取儲存庫 來設定 SSH 金鑰,和 簡易提交 獲得關於 Weblate 決定提交更改的資訊。

受保護的分支#

如果在受保護的分支上使用 Weblate,可以組態使用拉取請求,並執行翻譯的實際複查(對您不知道的語言可能有問題)。另一個方法是去掉對 Weblate 推送使用者的這個限制。

例如在 GitHub,這可以在儲存庫組態中進行:

../_images/github-protected.png

與其他相互影響#

Weblate 通過使用它的 API,使與他人的交流更容易。

簡易提交#

Weblate 會盡可能將同一作者的提交分組到一個提交中。這大大減少了提交的數量,但是如果您想同步版本控制系統(VCS )儲存庫,例如合併,您可能需要明確地告訴它去做提交(這對 Managers`群組是預設允許的,參見 :ref:`privileges)。

如果多個組件分享相同的儲存庫,需要分別將他們全部鎖定:

  • 某人另外更改了已經被更改的字串。

  • 來自上游的結合發生了。

  • 明確地請求了提交。

  • A file download is requested.

  • 更改比 組件組態 上定義為 Age of changes to commit 的時間段更陳舊。

提示

Commits are created for every component. So in case you have many components you will still see lot of commits. You might utilize 匯併 Git 提交 add-on in that case.

If you want to commit changes more frequently and without checking of age, you can schedule a regular task to perform a commit. This can be done using Periodic Tasks in Django 管理界面. First create desired Interval (for example 120 seconds). Then add new periodic task and choose weblate.trans.tasks.commit_pending as Task with {"hours": 0} as Keyword Arguments and desired interval.

用指令稿處理儲存庫#

自訂 Weblate 與儲存庫互動方式是 附加元件。關於如何通過外掛執行外部指令稿的資訊,請參見 Executing scripts from add-on

跨組件保持翻譯一致#

一旦具有多個翻譯組件,您會想要確保相同的字串具有相同的翻譯。這可以在幾個層次實現。

翻譯宣傳#

With 允許翻譯再用 enabled (what is the default, see 組件組態), all new translations are automatically done in all components with matching strings. Such translations are properly credited to currently translating user in all components.

備註

翻譯宣傳需要金鑰來匹配單語言翻譯格式,因此在建立翻譯金鑰匙請記住。

一致性檢查#

在字串不同時 不一致 會啟動檢查。您可以藉此來手動複查其差異,並選擇正確的翻譯。

自動翻譯#

Automatic translation based on different components can be way to synchronize the translations across components. You can either trigger it manually (see 自動翻譯) or make it run automatically on repository update using add-on (see 自動翻譯).