附加元件

Add-ons provide ways to customize and automate the translation workflow. Admins can add and manage add-ons from the OperationsAdd-ons menu of each respective translation project or component. Add-ons can be also installed site-wide in 管理介面.

提示

You can also configure add-ons using API, DEFAULT_ADDONS, or install_addon.

Add-ons that opt in to manual triggering can be run from add-on management or using the API. Results are recorded in the add-on activity log.

../_images/addons.webp

觸發附加元件的事件

附加元件安裝

Triggered when add-on is being installed.

組件更新

每當組件發生變化時觸發,例如:

  • Strings are changed in the repository.

  • 新增了新字串

  • 新增了新翻譯。

每天

Triggered daily, but add-ons usually split the daily load between components depending on BACKGROUND_TASKS.

事件變更

Triggered after a Change event is created.

手動觸發

Triggered when an add-on is run manually from add-on management or the API.

Repository post-add

Triggered just after the new translation is added and committed.

Repository post-commit

Triggered just after the changes are committed.

Repository post-push

Triggered just after the repository is pushed upstream.

Repository post-remove

Triggered just after a translation is removed.

Repository post-update

Triggered whenever new changes are pulled from the upstream repository.

Repository pre-commit

Triggered just before the changes are committed.

Repository pre-push

Triggered just before the repository is pushed upstream.

Repository pre-update

Triggered just before the repository update is attempted.

Unit post-save

Triggered just after the string is saved.

Unit post-sync

Triggered after the string is synchronized with the VCS.

Unit pre-create

Triggered just after the newly created string is saved.

內建附加元件

自動翻譯

附加元件 ID:

weblate.autotranslate.autotranslate

配置:

mode

自動翻譯模式

可用的選擇:

suggest

新增為建議

translate

新增為翻譯

fuzzy

加入並標為「需要編輯」

q

查詢

請注意:翻譯所有字串會捨棄所有現有翻譯。

auto_source

自動翻譯的來源

可用的選擇:

others

其他翻譯組件

mt

機器翻譯

component

組件

輸入要用作來源的組件 slug。留空則使用本專案的所有組件。

engines

機器翻譯引擎

機器翻譯引擎

threshold

分數閾值

觸發:

附加元件安裝, 組件更新, 每天, 事件變更

使用機器翻譯或其他組件來自動翻譯字串。

JavaScript 在地化 CDN

在 4.2 版被加入.

附加元件 ID:

weblate.cdn.cdnjs

配置:

threshold

最低翻譯數

翻譯字串必須達到的百分比,才能納入翻譯。

css_selector

CSS 選擇器

用來偵測可在地化元素的 CSS 選擇器。

cookie_name

語言 Cookie 名稱

儲存語言偏好設定的 Cookie 名稱。

files

從 HTML 檔案擷取字串

List of filenames in current repository or remote URLs to parse for translatable strings.

觸發:

附加元件安裝, 每天, Repository post-commit, Repository post-update

將翻譯發佈給內容遞交網路,供 JavaScript 或 HTML 在地化處理使用。

可以用於在地化靜態 HTML 網頁,或者在 JavaScript 程式碼中載入在地化檔案。

為您的組件產生一個唯一的 URL,您可以將其包含在 HTML 頁面中以在地化它們。請參閱 使用 Weblate CDN 翻譯 HTML 和 JavaScript 以了解詳情。

備註

This add-on requires additional configuration on the Weblate server. LOCALIZE_CDN_PATH configures where generated files will be written (on a filesystem), and LOCALIZE_CDN_URL defines where they will be served (URL). Serving of the files is not done by Weblate and has to be set up externally (typically using a CDN service).

This add-on is configured on Hosted Weblate and serves the files via https://weblate-cdn.com/.

移除空白字串

在 4.4 版被加入.

附加元件 ID:

weblate.cleanup.blank

配置:

This add-on has no configuration.

觸發:

附加元件安裝, Repository post-commit, Repository post-update

從翻譯檔案中移除沒有翻譯的字串。

使用此方法可以使翻譯檔案中不存在任何空字串(例如,如果您的在地化函式庫將它們顯示為缺失,而不是退回到來源字串)。

清理翻譯檔案

附加元件 ID:

weblate.cleanup.generic

配置:

This add-on has no configuration.

觸發:

附加元件安裝, Repository post-update, Repository pre-commit

更新所有翻譯檔案以符合單語言基礎檔。對大多數檔案格式而言,這代表會移除基礎檔中不再存在的失時效翻譯金鑰。

For formats containing additional content besides translation strings (such as HTML 檔案, Windows RC 檔案, or OpenDocument 格式) this also brings the translation file in sync with the base file.

加入遺漏語言

附加元件 ID:

weblate.consistency.languages

配置:

This add-on has no configuration.

觸發:

附加元件安裝, 每天, Repository post-add

確保對一個專案內所有組件使用一致的一組語言。

備註

The components shared from other projects are not considered in this.

每隔24小時,和在 Weblate 中加入新語言時,會檢查一次缺失的語言。

不像其他多數附加元件,這個附加元件影響整個專案。

提示

自動翻譯 自動翻譯新增加的字串。

組件探索

附加元件 ID:

weblate.discovery.discovery

配置:

match

用來比對出翻譯檔案的正規表達式

正規表達式必須定義名為「component」與「language」的命名群組。

file_format

檔案格式

檔案格式

name_template

自訂組件名稱

使用 Django 模板語法。這個模板必須包含 {{ component }}。

base_file_template

定義單語的基礎檔案名

雙語翻譯檔案請留空。若有設定,這個模板必須包含 {{ component }}。

new_base_template

定義新翻譯的基礎檔案

用來建立新翻譯的檔案名稱。例如 gettext,請選擇 .pot 檔。這個模板必須包含 {{ component }}。

intermediate_template

中間語言檔案

中間翻譯檔案的檔案名稱。大部分情況下,這即是開發者提供的翻譯檔案,會在建立實際來源字串時使用。這個模板必須包含 {{ component }}。

language_regex

語言篩選

掃描檔案遮罩時,用於篩選翻譯檔案的正規表達式。

copy_addons

將附加元件,從主要組件複製到新建立的組件

remove

移除無相關檔案的組件

觸發:

附加元件安裝, Repository post-update

根據版本控制系統中的檔案變更自動加入或移除專案組件。

The matching is done using regular expressions enabling complex configuration, but some knowledge is required to do so. The regular expression to match translation files has to contain two named groups to match component and language. All named groups in the regular expression can be used as variables in the template fields.

Discovery requirements

To discover a component successfully, the configuration has to do all of the following:

  • The regular expression must define component and language named groups.

  • Template fields used to name or locate per-component files must include {{ component }}, so the rendered value actually changes for each discovered component.

  • For monolingual formats, the component must contain a file matching base_file_template and at least one translation file matching match.

Worked example: news_<lang>.md

This is a common filename-based language variant layout:

  • docs/news_en.md

  • docs/news_cs.md

  • docs/guide_en.md

Use the Filename-based language variants preset for a starting point, then choose the matching file format and review the populated values.

正規表達式:

(?:(?P<path>.*/))?(?P<component>.+?)_(?P<language>[A-Za-z]{2,3}(?:[_-][A-Za-z0-9]+)*)\.(?P<extension>[^/.]+)

組件名稱:

{{ component }}

Discovered file masks:
  • docs/news_*.md

  • docs/guide_*.md

In this example, {{ component }} resolves to the basename before the language suffix, so docs/news_en.md, docs/news_pt_BR.md, and docs/news_pt-BR.md all become the news component.

You can use Django template markup in all filename fields, for example:

{{ component }}

Component name parsed from the component match group

{{ component|title }}

組件檔案名首字母大寫

{{ path }}: {{ component }}

Custom match group from the regular expression

一旦點選了 Save,將顯示匹配組件的預覽,可以檢查配置是否匹配於自己的需要:

../_images/addon-discovery.webp

組件探索範例

The worked example above covers the most common filename-based variant layout. The following examples show other repository structures you can match.

每個語言一個資料夾

各語言各一個資料夾包含組件的翻譯檔案。

正規表達式:

(?P<language>[^/.]*)/(?P<component>[^/]*)\.po

符合的檔案:
  • cs/application.po

  • cs/website.po

  • de/application.po

  • de/website.po

Gettext語言環境佈局

儲存 gettext PO 檔案的常用結構。

正規表達式:

locale/(?P<language>[^/.]*)/LC_MESSAGES/(?P<component>[^/]*)\.po

符合的檔案:
  • locale/cs/LC_MESSAGES/application.po

  • locale/cs/LC_MESSAGES/website.po

  • locale/de/LC_MESSAGES/application.po

  • locale/de/LC_MESSAGES/website.po

複雜的檔案名稱

檔案名同時使用組件名稱和語言名稱。

正規表達式:

src/locale/(?P<component>[^/]*)\.(?P<language>[^/.]*)\.po

符合的檔案:
  • src/locale/application.cs.po

  • src/locale/website.cs.po

  • src/locale/application.de.po

  • src/locale/website.de.po

重複的語言代碼

路徑和檔案名中都使用語言名稱。

正規表達式:

locale/(?P<language>[^/.]*)/(?P<component>[^/]*)/(?P=language)\.po

符合的檔案:
  • locale/cs/application/cs.po

  • locale/cs/website/cs.po

  • locale/de/application/de.po

  • locale/de/website/de.po

分離 Android 字串

Android 資源字串,切分為多份檔案。

正規表達式:

res/values-(?P<language>[^/.]*)/strings-(?P<component>[^/]*)\.xml

符合的檔案:
  • res/values-cs/strings-about.xml

  • res/values-cs/strings-help.xml

  • res/values-de/strings-about.xml

  • res/values-de/strings-help.xml

符合多個路徑

使用 Java properties 翻譯的多模組 Maven 專案管理。

正規表達式:

(?P<originalHierarchy>.+/)(?P<component>[^/]*)/src/main/resources/ApplicationResources_(?P<language>[^/.]*)\.properties

組件名稱:

{{ originalHierarchy }}: {{ component }}

符合的檔案:
  • parent/module1/submodule/src/main/resources/ApplicationResources_fr.properties

  • parent/module1/submodule/src/main/resources/ApplicationResource_es.properties

  • parent/module2/src/main/resources/ApplicationResource_de.properties

  • parent/module2/src/main/resources/ApplicationResource_ro.properties

提示

Component discovery add-on uses Weblate 內部 URL. It’s a convenient way to share VCS setup between multiple components. Linked components use the local repository of the main component set up by filling weblate://project/main-component into the 原始碼儲存庫 field (in OperationsSettingsVersion control system) of each respective component. This saves time with configuration and system resources too.

提示

Ensure the new component contains the full set of translatable languages with 加入遺漏語言.

Fedora 訊息

在 5.15 版被加入.

附加元件 ID:

weblate.fedora_messaging.publish

配置:

events

變更事件

變更事件

amqp_host

AMQP broker 主機

要連線的 AMQP broker。

amqp_ssl

使用 SSL 連線到 AMQP

ca_cert

CA 憑證

包含一組 PEM 編碼的 CA 憑證,用於驗證伺服器所出示的憑證。

client_key

用戶端 SSL 金鑰

編碼成 PEM 格式的用戶端私密 SSL 金鑰。

client_cert

用戶端 SSL 憑證

編碼成 PEM 格式的用戶端 SSL 憑證。

觸發:

事件變更

傳送通知到相容 Fedora Messaging 的 AMQP exchange。

Fedora Messaging是基於AMQP的發佈者,用於Weblate中發生的所有變化。您可以在使用此操作中掛鉤正在發生的變更的其他服務。

訊息主題

All messages have topic weblate.<action>.<project>.<component>.<translation>. The action is lowercase textual representation of action with underscores instead of space, for example resource_update, all other parts are optional and represent slug of the object or a language code.

訊息本體

The body consists of following fields (given that they are available for the event):

change_id

Numerical ID of change

action

Verbose name of the change.

timestamp

ISO 格式時間戳

target

New value of the change (eg. new translation of the string)

old

Old value of the change (eg. previous translation of the string)

source

來源字串。

url

檢視相關物件的絕對 URL。

author

Author username (this can be different from user for example when accepting suggestions)

user

Acting username

project

專案 slug

component

組件標識串

translation

翻譯語言代碼

訊息標頭

There are additional headers which you might utilize for routing as well:

action

Verbose name of the change.

project

專案 slug

component

組件標識串

範例訊息

儲存庫合併事件:

{
  "id": 1,
  "action": "Merged repository",
  "timestamp": "2017-06-15T11:30:47.325000+00:00",
  "url": "http://example.com/projects/test/test/",
  "component": "test"
}

新的來源字串事件:

{
  "id": 2,
  "action": "New source string",
  "timestamp": "2017-06-15T11:30:47.372000+00:00",
  "url": "http://example.com/translate/test/test/cs/?checksum=6412684aaf018e8e",
  "component": "test",
  "translation": "cs",
  "source": ["Hello, world!\n"]
}

資源更新事件:

{
  "id": 6,
  "action": "Resource update",
  "timestamp": "2017-06-15T11:30:47.410000+00:00",
  "url": "http://example.com/projects/test/test/cs/",
  "project": "test",
  "component": "test",
  "translation": "cs"
}
{
  "id": 7,
  "action": "Resource update",
  "timestamp": "2017-06-15T11:30:47.510000+00:00",
  "url": "http://example.com/projects/test/test/de/",
  "project": "test",
  "component": "test",
  "translation": "de"
}
{
  "id": 8,
  "action": "Resource update",
  "timestamp": "2017-06-15T11:30:47.595000+00:00",
  "url": "http://example.com/projects/test/test/it/",
  "project": "test",
  "component": "test",
  "translation": "it"
}

專案移除事件:

{
  "id": 9,
  "action": "Removed project",
  "timestamp": "2019-10-17T15:57:08.559420+00:00",
  "target": "test",
  "user": "testuser"
}

新貢獻者事件:

{
  "id": 11,
  "action": "New contributor",
  "timestamp": "2019-10-17T15:57:08.759960+00:00",
  "url": "http://example.com/translate/test/test/cs/?checksum=6412684aaf018e8e",
  "author": "testuser",
  "user": "testuser",
  "project": "test",
  "component": "test",
  "translation": "cs",
  "source": ["Hello, world!\n"]
}

新翻譯事件:

{
  "id": 12,
  "action": "New translation",
  "timestamp": "2019-10-17T15:57:08.772591+00:00",
  "url": "http://example.com/translate/test/test/cs/?checksum=6412684aaf018e8e",
  "target": ["Ahoj svete!\n"],
  "author": "testuser",
  "user": "testuser",
  "project": "test",
  "component": "test",
  "translation": "cs",
  "source": ["Hello, world!\n"]
}

大量編輯

附加元件 ID:

weblate.flags.bulk

配置:

q

查詢

state

要設定的狀態

可用的選擇:

-1

不變更

10

需要編輯

11

需要編輯(需要重新撰寫)

12

需要編輯(需要檢查)

20

已翻譯

30

已核可

add_flags

要加入的翻譯旗標

remove_flags

要移除的翻譯旗標

add_labels

要加入的標籤

remove_labels

要移除的標籤

觸發:

附加元件安裝, 組件更新

大量編輯字串的旗標、標籤或狀態。

範例:

自動標籤於新字串

搜尋查詢

NOT has:label

要加入的標籤

目前

Marking all App store 詮釋資料檔案 changelog strings read-only

搜尋查詢

language:en AND key:changelogs/

要加入的翻譯旗標

read-only

Marking certain strings read-only

搜尋查詢

source:r"^\`\`[.a-zA-Z0-9_-]*\`\`$" AND language:en

要加入的翻譯旗標

read-only

將未變動的翻譯標記為「需要重新撰寫」

附加元件 ID:

weblate.flags.same_edit

配置:

This add-on has no configuration.

觸發:

Unit pre-create

每當新的可翻譯字串從 VCS 匯入且符合來源字串時,會在 Weblate 中標記為需要重新撰寫。這對於未翻譯字串有來源字串的檔案格式來說特別有用。

提示

您或許也想要加強 未變更的翻譯 的檢查透過加入 strict-same 標記到 翻譯旗標 中。

也參考

翻譯狀態

標記新來源字串為「需要檢查」

附加元件 ID:

weblate.flags.source_edit

配置:

This add-on has no configuration.

觸發:

Unit pre-create

每當新來源字串由 VCS 匯入時,會在 Weblate 中標記為需要檢查。這樣您可以輕鬆篩選並編輯開發者寫的來源字串。

也參考

翻譯狀態

將新翻譯標記為「需要重新撰寫」

附加元件 ID:

weblate.flags.target_edit

配置:

This add-on has no configuration.

觸發:

Unit pre-create

每當新的可翻譯字串從 VCS 匯入時,會在 Weblate 中標記為需要重新撰寫。這樣您可以輕鬆篩選並編輯開發者建立的翻譯。

也參考

翻譯狀態

將儲存庫中更新的翻譯標記為「需要重新撰寫」

附加元件 ID:

weblate.flags.target_repo_update

配置:

This add-on has no configuration.

觸發:

Unit post-sync

當版本控制系統中的字串翻譯有變更時,Weblate 會將其標記為需要重新撰寫。這項功能在翻譯檔案經常被手動更新或由外部服務修改的情況下特別實用。

也參考

翻譯狀態

用原文填充唯讀字串

在 4.18 版被加入.

附加元件 ID:

weblate.generate.fill_read_only

配置:

This add-on has no configuration.

觸發:

附加元件安裝, 組件更新, 每天

將來源字串作為唯讀字串的翻譯填充。

統計資料產生器

附加元件 ID:

weblate.generate.generate

配置:

filename

產生的檔案名稱

template

產生的檔案內容

觸發:

附加元件安裝, Repository pre-commit

產生內含翻譯狀態詳細資訊的檔案。

您可以使用 Django 範本在檔案名或內容中,參閱: 範本標記 取得更多標記描述細節。

例如為每一個翻譯產生簡介檔案:

產生的檔案名稱

locale/{{ language_code }}.json

內容
{
   "language": "{{ language_code }}",
   "strings": "{{ stats.all }}",
   "translated": "{{ stats.translated }}",
   "last_changed": "{{ stats.last_changed }}",
   "last_author": "{{ stats.last_author }}",
}

也參考

範本標記

將原文預先填充進翻譯

在 4.11 版被加入.

附加元件 ID:

weblate.generate.prefill

配置:

This add-on has no configuration.

觸發:

附加元件安裝, 組件更新, 每天

用來源字串填充翻譯字串。

All untranslated strings in the component will be filled with the source string, and marked as needing edit. Use this when you can not have empty strings in the translation files. .. AUTOGENERATED START: weblate.generate.pseudolocale .. This section is automatically generated by ./manage.py list_addons. Do not edit manually.

偽語系產生

在 4.5 版被加入.

附加元件 ID:

weblate.generate.pseudolocale

配置:

source

來源字串

target

目標翻譯

本翻譯中的所有字串都將被覆寫

prefix

前置靜態文字

var_prefix

前置可變文字

suffix

後置靜態文字

var_suffix

後置可變文字

var_multiplier

可變文字乘數

根據來源字串的長度,決定變數文字要重複多少次。

include_readonly

納入唯讀字串

觸發:

附加元件安裝, 組件更新, 每天

藉由在來源字串加前綴與後綴,來自動產生偽語系翻譯。

偽 locale 對於尋找未準備好進行在地化的字串很有用。這是透過修改所有可翻譯的來源字串來實現的,使得在用偽 locale 語言執行應用程式時很容易發現未修改的字串。

發現在地化對應物可能不適合配置的字串也是可能的。

Using the variable parts makes it possible to look for strings which might not fit into the user interface after the localization - it extends the text based on the source string length. The variable texts are repeated by length of the text multiplied by the multiplier. For example Hello world with variable text _ and variable multiplier of 1 becomes Hello world___________ - the text is repeated once for each character in the source string.

字串將以下述模式產生:

Prepended static text Prepended variable text Source string Appended variable text Appended static text

提示

可以使用真正的語言進行檢測,但在 Weblate 中有專用的假語言環境——en_XAar_XB

提示

您可以使用這個擴充套件來開始翻譯現有或相似的語言。一旦您加入翻譯到這組件,也將會套用擴充套件。例如:您有 fr 且想加入 fr_CA 翻譯,只需要將 fr 設定來源語言,fr_CA 為目標翻譯,並將前字尾留空。

在填滿新翻譯後解除安裝擴充套件以防止 Weblate 變更複製後的翻譯。

評論中的貢獻者紀錄

附加元件 ID:

weblate.gettext.authors

配置:

This add-on has no configuration.

觸發:

Repository pre-commit

更新 PO 檔案標頭中的評論部分以納入貢獻者姓名及貢獻年份。

PO 檔案頭看上去是這樣的:

# Michal Čihař <michal@weblate.org>, 2012, 2018, 2019, 2020.
# Pavel Borecki <pavel@example.com>, 2018, 2019.
# Filip Hron <filip@example.com>, 2018, 2019.
# anonymous <noreply@weblate.org>, 2019.

更新「configure」檔案中的 ALL_LINGUAS 變數

附加元件 ID:

weblate.gettext.configure

配置:

This add-on has no configuration.

觸發:

附加元件安裝, 每天, Repository post-add, Repository post-remove

每當新增或移除翻譯時,更新「configure」、「configure.in」或「configure.ac」檔案中的 ALL_LINGUAS 變數。

Updates the ALL_LINGUAS variable in configure, configure.in or any configure.ac files, when a translation is added or removed.

自訂 gettext 輸出

在 5.13 版被移除: 檔案格式參數 取代。

更新 POT 檔案(Django)

在 5.17 版被加入.

附加元件 ID:

weblate.gettext.django

配置:

interval

更新頻率

當組件重新載入時,附加元件應以何種頻率更新 POT 檔案。

可用的選擇:

daily

每天

weekly

每週

monthly

每月

normalize_header

標準化 POT 標頭

更新 gettext 標頭並取代 POT 評論佔位字元。

觸發:

附加元件安裝, 手動觸發, Repository post-update

使用 Django 內建的 makemessages 指令更新 gettext 範本。

更新 LINGUAS 檔案

附加元件 ID:

weblate.gettext.linguas

配置:

This add-on has no configuration.

觸發:

附加元件安裝, 每天, Repository post-add, Repository post-remove

當新增或移除翻譯時更新 LINGUAS 檔案。

更新 POT 檔案 (Meson)

在 5.17 版被加入.

附加元件 ID:

weblate.gettext.meson

配置:

interval

更新頻率

當組件重新載入時,附加元件應以何種頻率更新 POT 檔案。

可用的選擇:

daily

每天

weekly

每週

monthly

每月

normalize_header

標準化 POT 標頭

更新 gettext 標頭並取代 POT 評論佔位字元。

comment_mode

程式碼評論

選擇 xgettext 是不要擷取評論、擷取所有評論,還是只擷取包含特定標籤的評論。

可用的選擇:

off

不要擷取評論

all

擷取所有評論

tagged

擷取包含標籤的評論

comment_tag

評論標記

在使用標籤評論模式時,傳遞給 xgettext 用於擷取評論的標籤。

checks

xgettext 檢查

針對擷取的訊息,要啟用的其他 xgettext 驗證檢查。

可用的選擇:

ellipsis-unicode

ellipsis-unicode

space-ellipsis

space-ellipsis

quote-unicode

quote-unicode

bullet-unicode

bullet-unicode

keyword

額外關鍵字

可選擇傳遞給 xgettext 的其他關鍵字,使用 --keyword 引數。

preset

Meson 預設

內建的 xgettext 引數預設組態,與 Meson 的 gettext 整合功能相符。這個 GLib 預設組態加上了 Meson 的 gettext 輔助程式所使用的關鍵字及格式旗標選項。

可用的選擇:

glib

GLib

觸發:

附加元件安裝, 手動觸發, Repository post-update

依照 Meson 的 gettext 慣例更新 gettext 範本。

產生 MO 檔案

附加元件 ID:

weblate.gettext.mo

配置:

path

產生的 MO 檔案路徑

如果未指定,將使用 PO 檔案的位置。

fuzzy

包含需要編輯的字串

需要編輯的字串 (fuzzy) 通常無法直接被用為翻譯。

觸發:

Repository pre-commit

每次 PO 檔案有變動時便自動產生 MO 檔案。

產生的 MO 檔案的位置可以客製化,並且其欄位使用 範本標記

備註

If a translation is removed, its PO file will be deleted from the repository, but the MO file generated by this add-on will not. The MO file must be removed from the upstream manually.

更新 PO 檔案以符合 POT (msgmerge)

在 5.13 版的變更: Settings configuration has been moved to 檔案格式參數.

附加元件 ID:

weblate.gettext.msgmerge

配置:

This add-on has no configuration.

觸發:

附加元件安裝, Repository post-update

使用 msgmerge 更新所有(在「檔案遮罩」設定的)PO 檔案以跟(在「新翻譯的範本」設定的)POT 檔案同步。

This add-on is essential when working with gettext PO files where the POT (template) file is updated with new strings or changes to existing strings. When the POT file is updated in the repository, this add-on automatically merges those changes into all language PO files, ensuring that:

  • New translatable strings appear in all languages

  • Removed strings are marked as obsolete

  • Modified strings are marked as needing review (fuzzy)

Most msgmerge command-line options can be set up through file format parameters configuration.

更新 POT 檔案(Sphinx)

在 5.17 版被加入.

附加元件 ID:

weblate.gettext.sphinx

配置:

interval

更新頻率

當組件重新載入時,附加元件應以何種頻率更新 POT 檔案。

可用的選擇:

daily

每天

weekly

每週

monthly

每月

normalize_header

標準化 POT 標頭

更新 gettext 標頭並取代 POT 評論佔位字元。

filter_mode

篩選中

可選擇在 Sphinx 擷取後移除不需要翻譯的字串。

可用的選擇:

none

weblate_docs

Weblate 文件

觸發:

附加元件安裝, 手動觸發, Repository post-update

使用 Sphinx 的 gettext builder 更新 gettext 範本,且不載入專案設定。

更新 POT 檔案 (xgettext)

在 5.17 版被加入.

附加元件 ID:

weblate.gettext.xgettext

配置:

interval

更新頻率

當組件重新載入時,附加元件應以何種頻率更新 POT 檔案。

可用的選擇:

daily

每天

weekly

每週

monthly

每月

normalize_header

標準化 POT 標頭

更新 gettext 標頭並取代 POT 評論佔位字元。

comment_mode

程式碼評論

選擇 xgettext 是不要擷取評論、擷取所有評論,還是只擷取包含特定標籤的評論。

可用的選擇:

off

不要擷取評論

all

擷取所有評論

tagged

擷取包含標籤的評論

comment_tag

評論標記

在使用標籤評論模式時,傳遞給 xgettext 用於擷取評論的標籤。

checks

xgettext 檢查

針對擷取的訊息,要啟用的其他 xgettext 驗證檢查。

可用的選擇:

ellipsis-unicode

ellipsis-unicode

space-ellipsis

space-ellipsis

quote-unicode

quote-unicode

bullet-unicode

bullet-unicode

keyword

額外關鍵字

可選擇傳遞給 xgettext 的其他關鍵字,使用 --keyword 引數。

input_mode

輸入來源

選擇要讓 xgettext 從 glob 樣式讀取來源檔案,或是從 POTFILES/POTFILES.in 資訊清單檔案讀取。

可用的選擇:

patterns

來源檔案形式

potfiles

POTFILES 資訊清單

language

xgettext 語言

傳遞給 xgettext 的程式語言,例如 Python 或 C。

source_patterns

來源檔案形式

以換列符號分隔的儲存庫相對路徑 glob 樣式,用來指定要使用 xgettext 擷取的檔案。

potfiles_path

POTFILES 路徑

指向 POTFILES 或 POTFILES.in 的儲存庫相對路徑。項目的解析以儲存庫根目錄為基準。若與資訊清單位於同一目錄,POTFILES.skip 會將列出的檔案排除在擷取範圍之外。

觸發:

附加元件安裝, 手動觸發, Repository post-update

使用 xgettext 針對選取的來源檔案更新 gettext 範本。

匯併 Git 提交

附加元件 ID:

weblate.git.squash

配置:

squash

提交匯併

可用的選擇:

all

所有提交匯併為一

language

每個語言

file

每個檔案

author

每位作者

append_trailers

在將多個提交壓縮(squash)為一個提交時,將某些特定的詮釋資料(trailers)附加到最終的提交資訊中

額外資訊的列看起來類似於 RFC 822 郵件信箱標頭,位於提交訊息的其他自由格式部分的末尾,例如「Co-authored-by: …」。

commit_message

提交訊息

此提交訊息將用來取代從壓縮提交組合而成的提交訊息。

觸發:

附加元件安裝, Repository post-commit

推送變更前先匯併 Git 提交。

提示

To avoid unnecessary conflicts, it is recommended to configure automatic receiving of upstream changes by webhooks or API, see 更新儲存庫.

以下模式之一中,Git提交可以在推送變更之前被壓縮:

  • 所有提交匯併為一

  • 每個語言

  • 每個檔案

  • 每位作者

Original commit messages are kept, but authorship is lost unless Per author is selected, or the commit message is customized to include it.

The original commit messages can optionally be overridden with a custom commit message.

預告(提交行像 Co-authored-by: )可選地從原始提交訊息中去掉,並且新增在去掉的提交訊息後面。這還可以為每一位翻譯者產生適當的 Co-authored-by: 信譽。

自訂 JSON 輸出

在 5.12 版的變更: Avoid spaces after separators option added.

在 5.13 版被移除: 檔案格式參數 取代。

重設儲存庫回上游狀態

在 5.17 版被加入.

附加元件 ID:

weblate.hosted.reset

配置:

This add-on has no configuration.

觸發:

附加元件安裝, 每天

每天晚上都丟棄在 Weblate 儲存庫中所有的變動。

格式化 Java properties 檔案

附加元件 ID:

weblate.properties.sort

配置:

case_sensitive

啟用區分大小寫的字串鍵排序

觸發:

Repository pre-commit

格式化並排序 Java properties 檔案。

  • 將新行合併為 Unix ones。

  • Unicode 跳脫符號的大寫格式(如果有的話)。

  • 替除空白行與評論。

  • 依鍵值排序字串。

  • 移除重複字串。

陳舊評論移除

附加元件 ID:

weblate.removal.comments

配置:

age

保留的天數

觸發:

附加元件安裝, 每天

設定移除評論的時間間隔。

這可以用於刪除可能變得過時的陳舊註釋。小心使用,因為陳舊的註釋不意味著失去了重要性。

陳舊建議移除

附加元件 ID:

weblate.removal.suggestions

配置:

age

保留的天數

votes

最低投票數

移除之最低票數。當停用投票時,這個欄位不會有效果。

觸發:

附加元件安裝, 每天

設定移除建議的時間間隔。

Can be very useful in connection with suggestion voting (see 同行評審) to remove suggestions which don't receive enough positive votes in a given timeframe.

更新 RESX 檔案

附加元件 ID:

weblate.resx.update

配置:

This add-on has no configuration.

觸發:

附加元件安裝, Repository post-update

更新所有翻譯檔案以符合單語言上游基底檔。未使用的字串將移除,新增加的字串將根據來源字串複製加入。

提示

如果只想刪除陳舊的翻譯鍵,那麼使用 清理翻譯檔案

Slack Webhooks

在 5.12 版被加入.

附加元件 ID:

weblate.webhook.slack

配置:

webhook_url

Webhook URL

events

變更事件

變更事件

觸發:

事件變更

根據選擇事件傳送通知到 Slack 頻道。

警告

The notification content might show HTML tags. This is a known issue that will be soon addressed; see https://github.com/WeblateOrg/weblate/issues/15056.

提示

To obtain a webhook URL, follow the steps outlined in the Slack Incoming Webhooks documentation

Webhook

在 5.11 版被加入.

在 5.15 版的變更: Compliance of the secret length with the specification is now validated.

附加元件 ID:

weblate.webhook.webhook

配置:

webhook_url

Webhook URL

secret

Webhook 金鑰

標準的 Webhook 金鑰是一個編碼成 Base64 的字串。

events

變更事件

變更事件

觸發:

事件變更

依照 Standard Webhooks 規範,根據選取的事件傳送通知到外部服務。

The request payload complies with the Weblate Messaging schema. The OpenAPI description can also be found at /api/docs/. Sample request body:

{
   "change_id": 99,
   "action": "Translation changed",
   "timestamp": "2019-08-24T14:15:22Z",
   "target": "Nazdar svete!",
   "old": "Nazdar!",
   "source": "Hello, world",
   "url": "/translate/project-slug/component-slug/cs/?checksum=46add148a53cab6f",
   "author": "author-username",
   "user": "user-username",
   "project": "project-slug",
   "component": "component-slug",
   "translation": "cs"
}

Sample request body with categories:

{
   "change_id": 8910,
   "action": "Component renamed",
   "timestamp": "2025-06-11T07:15:09Z",
   "target": ["new-name"],
   "old": ["component-slug"],
   "url": "/projects/project-slug/parent-category/child-category/sub-category/component-slug/",
   "user": "testuser",
   "project": "project-slug",
   "component": "component-slug",
   "category": [
      "sub-category",
      "child-category",
      "parent-category"
   ]
}

範例請求標頭:

{
   "webhook-id": "7f1c5477f6275a69af7b83236c20cb1a",
   "webhook-timestamp": "1748505623.044281",
   "webhook-signature": "v1,Ceo5qEr07ixe2NLpvHk3FH9bwy/WavXrAFQ/9tdO6mc="
}

The webhook-signature is a space separated list of HMAC signatures generated using the secret string, the request payload, the webhook-timestamp, and the webhook-id. This ensures the authenticity and integrity of the webhook request.

The provided secret is a base64 encoded string between 24 bytes (192 bits) and 64 bytes (512 bits). It can be prefixed with whsec_ for easy identification.

To verify a request, you can use the Webhook.verify method from the standardwebhooks library or an implementation of the "Standard Webhooks Specification".

過時的附加元件

自訂 XML 輸出

在 4.15 版被加入.

在 5.13 版被移除: 檔案格式參數 取代。

自訂 YAML 輸出

在 5.13 版被移除: 檔案格式參數 取代。

常見附加元件參數

機器翻譯引擎

可用的選擇:

alibaba

阿里巴巴

aws

Amazon 翻譯

anthropic

Anthropic

apertium-apy

Apertium APy

microsoft-translator

Azure AI 翻譯器

azure-openai

Azure OpenAI

baidu

Baidu

cyrtranslit

CyrTranslit

deepl

DeepL

glosbe

Glosbe

google-translate-api-v3

Google Cloud 翻譯進階版

google-translate

Google Cloud 翻譯基本版

ltengine

LTEngine

libretranslate

LibreTranslate

modernmt

ModernMT

mymemory

MyMemory

netease-sight

Netease Sight

ollama

Ollama

openai

OpenAI

sap-translation-hub

SAP Translation Hub

systran

Systran

weblate

Weblate

weblate-translation-memory

Weblate 翻譯記憶

yandex

Yandex

yandex-v2

Yandex v2

youdao-zhiyun

Youdao Zhiyun

tmserver

tmserver

檔案格式

可用的選擇:

apple-xliff

XLIFF 1.2 附 Apple 擴充功能

appstore

App store 詮釋資料檔案

arb

ARB 檔案

aresource

Android 字串資源

asciidoc

AsciiDoc 檔案

ass

Advanced SubStation Alpha 字幕檔案

catkeys

Haiku catkeys

cmp-resource

Compose Multiplatform 資源

csv

CSV 檔案

csv-multi

多值 CSV 檔案

csv-simple

簡易 CSV 檔案

dokuwiki

DokuWiki 文字檔案

dtd

DTD 檔案

flatxml

Flat XML 檔案

fluent

Fluent 檔案

formatjs

Format.JS JSON 檔案

go-i18n-json

go-i18n v1 JSON 檔案

go-i18n-json-v2

go-i18n v2 JSON 檔案

go-i18n-toml

go-i18n TOML 檔案

gotext

gotext JSON 檔案

gwt

GWT 屬性

html

HTML 檔案

i18next

i18next JSON 檔案 v3

i18nextv4

i18next JSON 檔案 v4

idml

IDML 檔案

ini

INI 檔案

islu

Inno Setup INI 檔案

joomla

Joomla 語言檔案

json

JSON 檔案

json-nested

JSON 巢狀結構檔案

laravel

Laravel PHP 字串

markdown

Markdown 檔案

mdx

MDX file

mediawiki

MediaWiki 文字檔案

mi18n-lang

@draggable/i18n 語言檔案

moko-resource

Mobile Kotlin 資源

nextcloud-json

Nextcloud JSON 檔案

odf

OpenDocument 檔案

php

PHP 字串

plainxliff

XLIFF 1.2 翻譯檔案

po

gettext PO 檔案

po-mono

gettext PO 檔案(單語)

poxliff

XLIFF 1.2 附 gettext 擴充功能

properties

Java 屬性

rc

RC 檔案

resjson

RESJSON 檔案

resourcedictionary

ResourceDictionary 檔案

resx

.NET 資源檔案

ruby-yaml

Ruby YAML 檔案

srt

SubRip 字幕檔案

ssa

SubStation Alpha 字幕檔案

strings

iOS 字串

stringsdict

Stringsdict 檔案

sub

MicroDVD 字幕檔案

tbx

TermBase eXchange 檔案

toml

TOML 檔案

ts

Qt Linguist 翻譯檔案

txt

純文字檔案

webextension

WebExtension JSON 檔案

wxl

WixLocalization 檔案

xliff

包含佔位字串支援的 XLIFF 1.2

xliff2

XLIFF 2.0 翻譯檔案

xliff2-placeables

包含佔位字串支援的 XLIFF 2.0

xlsx

Excel Open XML

xwiki-fullpage

XWiki Full Page

xwiki-java-properties

XWiki Java Properties

xwiki-page-properties

XWiki 頁面屬性

yaml

YAML 檔案

變更事件

可用的選擇:

0

資源已更新

1

完成了翻譯

2

變更了翻譯

3

新增了評論

4

新增了建議

5

新增了翻譯

6

自動翻譯

7

接受了建議

8

還原了翻譯

9

上傳了翻譯

13

新增了原文

14

鎖定了組件

15

解除了組件鎖定

17

已提交變更

18

已推送變更

19

已重設儲存庫

20

已合併儲存庫

21

已 rebase 儲存庫

22

儲存庫合併失敗

23

儲存庫 rebase 失敗

24

解析失敗

25

移除了翻譯

26

移除了建議

27

取代了翻譯

28

儲存庫推送失敗

29

在清理時移除了建議

30

來源字串有變更

31

新增了字串

32

已變更大量狀態

33

已變更可見性

34

新增了使用者

35

移除了使用者

36

核可了翻譯

37

標記為需要編輯

38

移除了組件

39

移除了專案

41

重新命名了專案

42

重新命名了組件

43

移動了組件

45

有新貢獻者加入

46

發佈了公告

47

觸發了警告

48

新增了語言

49

已請求加入語言

50

建立了專案

51

建立了組件

52

邀請了使用者

53

收到儲存庫通知

54

上傳並取代了翻譯檔案

55

已變更授權

56

已變更貢獻者授權契約

57

新增了畫面擷圖

58

上傳了畫面擷圖

59

儲存庫有更新字串

60

已安裝附加元件

61

已變更附加元件配置

62

已解除安裝附加元件

63

移除了字串

64

移除了評論

65

解決了評論

66

更新了解釋

67

移除了類別

68

重新命名了類別

69

移動了類別

70

儲存字串失敗

71

儲存庫有加入字串

72

上傳的檔案更新了字串

73

上傳的檔案新增了字串

74

透過上傳原文更新了翻譯

75

完成了組件翻譯

76

套用了強制檢查

77

傳播了變更

78

檔案已上傳

79

附加標記已更新

80

字型已上傳

81

字型已變更

82

字型已移除

83

已強制同步翻譯

84

已強制重新掃描翻譯

85

擷圖已移除

86

標籤已移除

87

標籤已移除

88

儲存庫清理

89

在上傳時新增了來源字串

90

在儲存庫中新增了來源字串

91

已備份專案

92

已還原專案

93

已還原組件

94

還原了使用者編輯

95

Project setting changed

96

Component setting changed

自訂附加元件清單

附加元件清單由 WEBLATE_ADDONS 進行配置。要新增其他附加元件,只需在這個設定中包含絕對類別名稱即可。

編寫附加元件

您也可以編寫自己的附加元件,建立子類別 weblate.addons.base.BaseAddon 來定義附加元件詮釋資料,接著實施 callback 來進行處理。

也參考

開發附加元件

從附加元件執行指令稿

附加元件還可以用於執行外部指令碼。這曾經整合在 Weblate 中,但現在必須寫一些代碼,將指令碼包裹在附加元件中。

# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""Example pre commit script."""

from __future__ import annotations

from typing import ClassVar

from django.utils.translation import gettext_lazy

from weblate.addons.events import AddonEvent
from weblate.addons.scripts import BaseScriptAddon


class ExamplePreAddon(BaseScriptAddon):
    # Event used to trigger the script
    events: ClassVar[set[AddonEvent]] = {
        AddonEvent.EVENT_PRE_COMMIT,
    }
    # Name of the addon, has to be unique
    name = "weblate.example.pre"
    # Verbose name and long description
    verbose = gettext_lazy("Execute script before commit")
    description = gettext_lazy("This add-on executes a script.")

    # Script to execute
    script = "/bin/true"
    # File to add in commit (for pre commit event)
    # does not have to be set
    add_file = "po/{{ language_code }}.po"

安裝方法請參閱 自訂的品質檢查、附加元件與自動修復

對於任何給定的組件,目前路徑設定為版本控制系統( VCS )儲存庫的根目錄時,執行指令稿。

此外,可以存取後面的環境參數:

WL_VCS

使用的版本控制系統。

WL_REPO

上游儲存庫 URL。

WL_PATH

版本控制系統( VCS )儲存庫的絕對路徑。

WL_BRANCH

目前組件配置的儲存庫分支。

WL_FILEMASK

目前組件的File mask。

WL_TEMPLATE

單語言翻譯範本的檔案名(可以為空)。

WL_NEW_BASE

建立新的翻譯所使用檔案的檔案名稱(可以為空)。

WL_FILE_FORMAT

在目前專案中使用的檔案格式。

WL_LANGUAGE

目前處理的翻譯的語言(對於組件級別的鉤子不可用)。

WL_PREVIOUS_HEAD

更新後的上個 HEAD (僅在執行更新後鉤子後可用)。

WL_COMPONENT_SLUG

組件標識串用於建構 URL。

WL_PROJECT_SLUG

Project slug used to construct URL.

WL_COMPONENT_NAME

組件名稱。

WL_PROJECT_NAME

專案名稱。

WL_COMPONENT_URL

組件 URL。

WL_ENGAGE_URL

專案參與 URL。

也參考

組件配置

Post-update repository processing

當 VCS 的上游來源發生變化時,可用於更新翻譯檔案。為了實現這個功能,請記住 Weblate 只看到提交給版本控制系統( VCS )的檔案,所以需要同意變更作為指令碼的一部分。

例如 Gulp,可以使用後面的程式碼來執行:

#! /bin/sh
gulp --gulpfile gulp-i18n-extract.js
git commit -m 'Update source strings' src/languages/en.lang.json

Pre-commit 翻譯處理

在將翻譯提交到儲存庫之前,使用提交指令稿自動變更翻譯。

它作為組成目前翻譯檔案名的單一參數而透過。

附加元件活動紀錄

Add-on activity log keeps track of the add-on execution and can be used to keep track of add-on activity.

The logs can be pruned after a certain time interval by configuring the ADDON_ACTIVITY_LOG_EXPIRY.