持續本地化

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

也參考

與 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更新存儲庫時,更新後插件都將被觸發,請參見: 附加元件

Avoiding merge conflicts

當相同的文件在 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 中完成。

也參考

Azure DevOps 手冊中的Web hooks, :http:post:` /hooks/azure/, :ref:`hosted-push

從 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。

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

如果不想要Weblate 的直接推送,系統也支持:ref:vcs-githubGitLab merge requestsvcs-pagure`的拉取請求或:ref:`vcs-gerrit`審核。你可以通過在:ref:`component 中選擇:guilabel:GitHubGitLabGerrit 或:guilabel:Pagure 作為:ref:component-vcs 來激活這些。

整體上, 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 merge requests

來自分支的 GitLab 結合請求

GitLab merge requests

SSH URL 1

分支名稱

來自分叉的Pargue合併請求

Pagure merge requests

來自分支的 Pagure合併請求

Pagure merge requests

SSH URL 1

分支名稱

1(1,2,3)

源始碼儲存庫 支持推送的情況下可以為空。

備註

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

也參考

請參見 Accessing repositories 來設置 SSH 密鑰,和 惰性提交 獲得關於 Weblate 決定提交更改的信息。

受保護的分支

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

例如在 GitHub,這可以在倉庫配置中進行:

../_images/github-protected.png

Interacting with others

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.

如果想要更頻繁地提交更改,並且不檢查新舊,可以安排週期定時性任務來執行提交:

CELERY_BEAT_SCHEDULE = {
    # Unconditionally commit all changes every 2 minutes
    "commit": {
        "task": "weblate.trans.tasks.commit_pending",
        # Omitting hours will honor per component settings,
        # otherwise components with no changes older than this
        # won't be committed
        "kwargs": {"hours": 0},
        # How frequently to execute the job in seconds
        "schedule": 120,
    }
}

用腳本處理倉庫

The way to customize how Weblate interacts with the repository is 附加元件. Consult Executing scripts from add-on for info on how to execute external scripts through add-ons.

跨組件保持翻譯一致

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

翻譯宣傳

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 自動翻譯).