持續本地化

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

也參考

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

這是過程:

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

  2. 可以選擇更新翻譯文件(這取決於文件格式,請參閱 當已經更新了模板時,為什麼 Weblate 仍然顯示舊的字串?)。

  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 之內的新字串,並將文件的整個編輯留在那裡。對於雙語言文件,通常存在某種消息提取過程而從原始碼產生翻譯文件。在一些情況下,這可以分成兩部分——一部分用於提取過程產生模板(例如使用:program:xgettext 產生gettex 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 自動接受更改

在 3.3 版本新加入.

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

../_images/pagure-webhook.png

從 Azure Repos 自動接收更改

在 3.8 版本新加入.

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 自動接收更改

在 3.9 版本新加入.

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

從 Gitee Repos 自動接收更改

在 3.9 版本新加入.

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

分支名稱

來自叉子的 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 )倉儲,例如合併,您可能需要明確地告訴它去做提交(這對:guilabel: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 自動翻譯).