附加元件

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.

../_images/addons.webp

Events that trigger add-ons

Add-on installation

Triggered when add-on is being installed.

Component update

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

  • Strings are changed in the repository.

  • A string is added.

  • A new translation is added.

Daily

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

Event change

Triggered after a Change event is created.

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-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.

內建附加元件

自動翻譯

Add-on ID:

weblate.autotranslate.autotranslate

組態:

mode

自動翻譯模式

Available choices:

suggest

新增為建議

translate

新增為翻譯

fuzzy

加入並標為「需要編輯」

q

查詢

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

auto_source

自動翻譯的來源

Available choices:

others

其他翻譯組件

mt

機器翻譯

component

組件

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

engines

機器翻譯引擎

機器翻譯引擎

threshold

分數閾值

觸發:

Add-on installation, Component update, Daily, Event change

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

JavaScript 在地化 CDN

在 4.2 版被加入.

Add-on ID:

weblate.cdn.cdnjs

組態:

threshold

最低翻譯數

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

css_selector

CSS 選擇器

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

cookie_name

語言 Cookie 名稱

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

files

從 HTML 檔案擷取字串

在目前儲存庫或遠端網址中,要剖析其可翻譯字串的檔案名稱列表。

觸發:

Add-on installation, Daily, 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 版被加入.

Add-on ID:

weblate.cleanup.blank

組態:

This add-on has no configuration.

觸發:

Add-on installation, Repository post-commit, Repository post-update

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

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

清理翻譯檔

Add-on ID:

weblate.cleanup.generic

組態:

This add-on has no configuration.

觸發:

Add-on installation, 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.

加入遺漏語言

Add-on ID:

weblate.consistency.languages

組態:

This add-on has no configuration.

觸發:

Add-on installation, Daily, Repository post-add

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

備註

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

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

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

提示

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

組件探索

Add-on ID:

weblate.discovery.discovery

組態:

match

用來比對出翻譯檔的常規表示式

file_format

檔案格式

檔案格式

name_template

自訂組件名稱

base_file_template

定義單語的基礎檔名

保留雙語翻譯檔空白。

new_base_template

定義新翻譯的基礎檔

用來建立新翻譯的檔案名稱。例如 gettext,請選擇 .pot 檔。

intermediate_template

中間語言檔案

中間翻譯檔的檔名。大部分情況下,這即是開發者提供的翻譯檔,會在建立實際來源字串時使用。

language_regex

語言篩選

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

copy_addons

將附加元件,從主要組件拓製到新創建的組件

remove

移除無相關檔案的組件

confirm

我能確認上述符合專案看起來正確

觸發:

Add-on installation, Repository post-update

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

該匹配是使用允許複雜組態的正規表達式完成的,但這樣做需要一些知識。一些常見用例的例子可以在附加元件幫助部分找到。

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.

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

{{ component }}

組件檔名比對

{{ component|title }}

組件檔名首字母大寫

{{ path }}: {{ component }}

Custom match group from the regular expression

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

../_images/addon-discovery.webp

Component discovery examples

One folder per language

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

常規表達式:

(?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

Repeated language code

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

常規表達式:

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

Split Android strings

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

Matching multiple paths

使用 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 內部網址. 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 加入遺漏語言.

警告

To be discovered, a new component must contain a file that matches base_file_template and at least one file with a name that matches match -- i.e., the component must contain a base language file and at least one existing translation. Otherwise, it will be ignored.

Fedora Messaging

在 5.15 版被加入.

Add-on ID:

weblate.fedora_messaging.publish

組態:

events

變更事件

變更事件

amqp_host

AMQP broker host

The AMQP broker to connect to.

amqp_ssl

Use SSL for AMQP connection

ca_cert

CA certificates

Bundle of PEM encoded CA certificates used to validate the certificate presented by the server.

client_key

Client SSL key

PEM encoded client private SSL key.

client_cert

Client SSL certificates

PEM encoded client SSL certificate.

觸發:

Event change

Sends notifications to a Fedora Messaging compatible AMQP exchange.

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

Message topic

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.

Message body

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 formatted timestamp

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

Source string.

url

Absolute URL to view the related object.

author

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

user

Acting username

project

項目標識串

component

組件標識串

translation

翻譯語言代碼

Message headers

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

action

Verbose name of the change.

project

項目標識串

component

組件標識串

Example messages

Repository merge event:

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

New source string event:

{
  "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"]
}

Resource update event:

{
  "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"
}

Project removal event:

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

New contributor event:

{
  "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"]
}

New translation event:

{
  "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"]
}

大量編輯

Add-on ID:

weblate.flags.bulk

組態:

q

查詢

state

要設定的狀態

Available choices:

-1

不變更

10

需要編輯

11

Needs rewriting

12

Needs checking

20

已翻譯

30

已核可

add_flags

要加入的翻譯旗標

remove_flags

要移除的翻譯旗標

add_labels

要加入的標籤

remove_labels

要移除的標籤

觸發:

Add-on installation, Component update

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

範例:

自動標籤於新字串

搜尋查詢

NOT has:label

要加入的標籤

recent

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

將未變動的翻譯標記為「需要編輯」

Add-on ID:

weblate.flags.same_edit

組態:

This add-on has no configuration.

觸發:

Unit pre-create

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

提示

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

也參考

翻譯狀態

標記新來源字串為「需要編輯」

Add-on ID:

weblate.flags.source_edit

組態:

This add-on has no configuration.

觸發:

Unit pre-create

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

也參考

翻譯狀態

將新翻譯標記為「需要編輯」

Add-on ID:

weblate.flags.target_edit

組態:

This add-on has no configuration.

觸發:

Unit pre-create

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

也參考

翻譯狀態

將儲存庫中更新的翻譯標記為「需要編輯」

Add-on ID:

weblate.flags.target_repo_update

組態:

This add-on has no configuration.

觸發:

Unit post-sync

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

也參考

翻譯狀態

用原文填充唯讀字串

在 4.18 版被加入.

Add-on ID:

weblate.generate.fill_read_only

組態:

This add-on has no configuration.

觸發:

Add-on installation, Component update, Daily

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

統計數據產生器

Add-on 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 版被加入.

Add-on ID:

weblate.generate.prefill

組態:

This add-on has no configuration.

觸發:

Add-on installation, Component update, Daily

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

所有在此元件中未翻譯的字串將會使用來源字串取代,並標記為需要編輯。請使用此功能當您不允許有空字串於翻譯檔案。

偽語系產生

在 4.5 版被加入.

Add-on ID:

weblate.generate.pseudolocale

組態:

source

來源字串

target

目標翻譯

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

prefix

前置靜態文字

var_prefix

前置可變文字

suffix

後置靜態文字

var_suffix

後置可變文字

var_multiplier

可變文字乘數

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

include_readonly

納入唯讀字串

觸發:

Add-on installation, Component update, Daily

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

偽 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 更改複製後的翻譯。

評註中的貢獻者紀錄

Add-on 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 變數

Add-on ID:

weblate.gettext.configure

組態:

This add-on has no configuration.

觸發:

Add-on installation, Daily, Repository post-add

當新的翻譯新增時,更新 configureconfigure.in 或任何 configure.ac 檔案中的 ALL_LINGUAS 變數。

自訂 gettext 輸出

在 5.13 版被移除: Replaced by 檔案格式參數.

更新 LINGUAS 檔案

Add-on ID:

weblate.gettext.linguas

組態:

This add-on has no configuration.

觸發:

Add-on installation, Daily, Repository post-add

當新增翻譯時更新 LINGUAS 檔。

產生 MO 檔案

Add-on 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 檔案格式參數.

Add-on ID:

weblate.gettext.msgmerge

組態:

This add-on has no configuration.

觸發:

Add-on installation, Repository post-update

Updates all PO files (as configured by 檔案遮罩) to match the POT file (as configured by 新翻譯的模板) using msgmerge.

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.

匯併 Git 送交

Add-on ID:

weblate.git.squash

組態:

squash

送交匯併

Available choices:

all

所有送交匯併為一

language

每個語言

file

每個檔案

author

每位作者

append_trailers

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

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

commit_message

送交訊息

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

觸發:

Add-on installation, 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 版被移除: Replaced by 檔案格式參數.

格式化 Java properties 檔案

Add-on ID:

weblate.properties.sort

組態:

case_sensitive

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

觸發:

Repository pre-commit

格式化並排序 Java properties 檔案。

  • 將新行合併為 Unix ones。

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

  • 替除空白行與評註。

  • 依鍵值排序字串。

  • 移除重複字串。

陳舊評註移除

Add-on ID:

weblate.removal.comments

組態:

age

保留的天數

觸發:

Add-on installation, Daily

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

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

陳舊建議移除

Add-on ID:

weblate.removal.suggestions

組態:

age

保留的天數

votes

最低投票數

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

觸發:

Add-on installation, Daily

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

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 檔案

Add-on ID:

weblate.resx.update

組態:

This add-on has no configuration.

觸發:

Add-on installation, Repository post-update

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

提示

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

Slack Webhooks

在 5.12 版被加入.

Add-on ID:

weblate.webhook.slack

組態:

webhook_url

Webhook 網址

events

變更事件

變更事件

觸發:

Event change

根據選擇事件傳送通知到 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.

Add-on ID:

weblate.webhook.webhook

組態:

webhook_url

Webhook 網址

secret

Webhook secret

The Standard Webhooks secret is a base64 encoded string.

events

變更事件

變更事件

觸發:

Event change

依照 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"
   ]
}

Sample request headers:

{
   "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 版被移除: Replaced by 檔案格式參數.

自訂 YAML 輸出

在 5.13 版被移除: Replaced by 檔案格式參數.

Common add-on parameters

機器翻譯引擎

Available choices:

aws

Amazon Translate

deepl

DeepL

google-translate-api-v3

Google Cloud Translation Advanced

google-translate

Google Cloud Translation Basic

modernmt

ModernMT

openai

OpenAI

weblate

Weblate

weblate-translation-memory

Weblate 翻譯記憶

變更事件

Available choices:

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

Screenshot removed

86

Label added

87

Label removed

檔案格式

Available choices:

appstore

App store 中介資料檔案

arb

ARB 檔

aresource

Android 字串資源

ass

Advanced SubStation Alpha 字幕檔

catkeys

Haiku catkeys

cmp-resource

Compose Multiplatform 資源

csv

CSV 檔

csv-multi-utf-8

多值 CSV 檔案 (UTF-8)

csv-simple

簡易 CSV 檔

csv-simple-iso

簡易 CSV 檔(ISO-8859-1)

csv-simple-utf-8

簡易 CSV 檔 (UTF-8)

csv-utf-8

CSV 檔案 (UTF-8)

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 file

gotext

gotext JSON 檔

gwt

GWT 屬性 (UTF-8)

gwt-iso

GWT 屬性 (ISO-8859-1)

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 檔案

mediawiki

MediaWiki 文本文件

mi18n-lang

@draggable/i18n 語言檔案

moko-resource

Mobile Kotlin 資源

nextcloud-json

Nextcloud JSON file

odf

OpenDocument 檔

php

PHP 字串

plainxliff

XLIFF 1.2 翻譯檔

po

gettext PO 檔

po-mono

gettext PO 檔(單語)

poxliff

XLIFF 1.2 附 gettext 擴充功能

properties

Java 屬性(ISO 8859-1)

properties-utf16

Java 屬性(UTF-16)

properties-utf8

Java 屬性(UTF-8)

rc

RC 檔

resjson

RESJSON file

resourcedictionary

ResourceDictionary 檔案

resx

.NET 資源檔

ruby-yaml

Ruby YAML 檔

srt

SubRip 字幕檔

ssa

SubStation Alpha 字幕檔

strings

iOS 字串 (UTF-16)

strings-utf8

iOS 字串 (UTF-8)

stringsdict

Stringsdict 檔案

sub

MicroDVD 字幕檔

tbx

TermBase eXchange 檔案

toml

TOML file

ts

Qt Linguist 翻譯檔

txt

純文字檔案

webextension

WebExtension JSON 檔

xliff

包含 placeables 支援的 XLIFF 1.2

xliff2

XLIFF 2.0 translation file

xliff2-placeables

XLIFF 2.0 translation file with placeables support

xlsx

Excel Open XML

xwiki-fullpage

XWiki Full Page

xwiki-java-properties

XWiki Java Properties

xwiki-page-properties

XWiki Page Properties

yaml

YAML 檔

自訂附加元件列表

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

Writing add-on

您也可以編寫自己的附加元件,建立子類別 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"

安裝方法請參見 Custom quality checks, add-ons, automatic suggestions and auto-fixes

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

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

WL_VCS

使用的版本控制系統。

WL_REPO

上游儲存庫的網址。

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

專案標識串用於建構 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 logging

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.