附加元件¶
Add-ons provide ways to customize and automate the translation workflow. Admins can add and manage add-ons from the Operations ↓ Add-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.
觸發附加元件的事件¶
附加元件安裝¶
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.
內建附加元件¶
自動翻譯¶
使用機器翻譯或其他組件來自動翻譯字串。
JavaScript 在地化 CDN¶
在 4.2 版被加入.
- 附加元件 ID:
weblate.cdn.cdnjs- 配置:
threshold最低翻譯數
翻譯字串必須達到的百分比,才能納入翻譯。
css_selectorCSS 選擇器
用來偵測可在地化元素的 CSS 選擇器。
cookie_name語言 Cookie 名稱
儲存語言偏好設定的 Cookie 名稱。
files從 HTML 檔案擷取字串
List of filenames in current repository or remote URLs to parse for translatable strings.
- 觸發:
將翻譯發佈給內容遞交網路,供 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.
- 觸發:
從翻譯檔案中移除沒有翻譯的字串。
使用此方法可以使翻譯檔案中不存在任何空字串(例如,如果您的在地化函式庫將它們顯示為缺失,而不是退回到來源字串)。
清理翻譯檔案¶
- 附加元件 ID:
weblate.cleanup.generic- 配置:
This add-on has no configuration.
- 觸發:
更新所有翻譯檔案以符合單語言基礎檔。對大多數檔案格式而言,這代表會移除基礎檔中不再存在的失時效翻譯金鑰。
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.
- 觸發:
確保對一個專案內所有組件使用一致的一組語言。
備註
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移除無相關檔案的組件
- 觸發:
根據版本控制系統中的檔案變更自動加入或移除專案組件。
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
componentandlanguagenamed 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_templateand at least one translation file matchingmatch.
Worked example: news_<lang>.md¶
This is a common filename-based language variant layout:
docs/news_en.mddocs/news_cs.mddocs/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_*.mddocs/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
componentmatch group{{ component|title }}組件檔案名首字母大寫
{{ path }}: {{ component }}Custom match group from the regular expression
一旦點選了 Save,將顯示匹配組件的預覽,可以檢查配置是否匹配於自己的需要:
組件探索範例¶
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.pocs/website.pode/application.pode/website.po
Gettext語言環境佈局¶
儲存 gettext PO 檔案的常用結構。
- 正規表達式:
locale/(?P<language>[^/.]*)/LC_MESSAGES/(?P<component>[^/]*)\.po- 符合的檔案:
locale/cs/LC_MESSAGES/application.polocale/cs/LC_MESSAGES/website.polocale/de/LC_MESSAGES/application.polocale/de/LC_MESSAGES/website.po
複雜的檔案名稱¶
檔案名同時使用組件名稱和語言名稱。
- 正規表達式:
src/locale/(?P<component>[^/]*)\.(?P<language>[^/.]*)\.po- 符合的檔案:
src/locale/application.cs.posrc/locale/website.cs.posrc/locale/application.de.posrc/locale/website.de.po
重複的語言代碼¶
路徑和檔案名中都使用語言名稱。
- 正規表達式:
locale/(?P<language>[^/.]*)/(?P<component>[^/]*)/(?P=language)\.po- 符合的檔案:
locale/cs/application/cs.polocale/cs/website/cs.polocale/de/application/de.polocale/de/website/de.po
分離 Android 字串¶
Android 資源字串,切分為多份檔案。
- 正規表達式:
res/values-(?P<language>[^/.]*)/strings-(?P<component>[^/]*)\.xml- 符合的檔案:
res/values-cs/strings-about.xmlres/values-cs/strings-help.xmlres/values-de/strings-about.xmlres/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.propertiesparent/module1/submodule/src/main/resources/ApplicationResource_es.propertiesparent/module2/src/main/resources/ApplicationResource_de.propertiesparent/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 Operations ↓ Settings ↓
Version 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_hostAMQP broker 主機
要連線的 AMQP broker。
amqp_ssl使用 SSL 連線到 AMQP
ca_certCA 憑證
包含一組 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_idNumerical ID of change
actionVerbose name of the change.
timestampISO 格式時間戳
targetNew value of the change (eg. new translation of the string)
oldOld value of the change (eg. previous translation of the string)
source來源字串。
url檢視相關物件的絕對 URL。
authorAuthor username (this can be different from user for example when accepting suggestions)
userActing username
project專案 slug
component組件標識串
translation翻譯語言代碼
訊息標頭¶
There are additional headers which you might utilize for routing as well:
actionVerbose 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要移除的標籤
- 觸發:
大量編輯字串的旗標、標籤或狀態。
範例:
搜尋查詢 |
|
|---|---|
要加入的標籤 |
目前 |
搜尋查詢 |
|
|---|---|
要加入的翻譯旗標 |
|
搜尋查詢 |
|
|---|---|
要加入的翻譯旗標 |
|
將未變動的翻譯標記為「需要重新撰寫」¶
- 附加元件 ID:
weblate.flags.same_edit- 配置:
This add-on has no configuration.
- 觸發:
每當新的可翻譯字串從 VCS 匯入且符合來源字串時,會在 Weblate 中標記為需要重新撰寫。這對於未翻譯字串有來源字串的檔案格式來說特別有用。
也參考
標記新來源字串為「需要檢查」¶
- 附加元件 ID:
weblate.flags.source_edit- 配置:
This add-on has no configuration.
- 觸發:
每當新來源字串由 VCS 匯入時,會在 Weblate 中標記為需要檢查。這樣您可以輕鬆篩選並編輯開發者寫的來源字串。
也參考
將新翻譯標記為「需要重新撰寫」¶
- 附加元件 ID:
weblate.flags.target_edit- 配置:
This add-on has no configuration.
- 觸發:
每當新的可翻譯字串從 VCS 匯入時,會在 Weblate 中標記為需要重新撰寫。這樣您可以輕鬆篩選並編輯開發者建立的翻譯。
也參考
將儲存庫中更新的翻譯標記為「需要重新撰寫」¶
- 附加元件 ID:
weblate.flags.target_repo_update- 配置:
This add-on has no configuration.
- 觸發:
當版本控制系統中的字串翻譯有變更時,Weblate 會將其標記為需要重新撰寫。這項功能在翻譯檔案經常被手動更新或由外部服務修改的情況下特別實用。
也參考
用原文填充唯讀字串¶
在 4.18 版被加入.
將來源字串作為唯讀字串的翻譯填充。
統計資料產生器¶
- 附加元件 ID:
weblate.generate.generate- 配置:
filename產生的檔案名稱
template產生的檔案內容
- 觸發:
產生內含翻譯狀態詳細資訊的檔案。
您可以使用 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 版被加入.
用來源字串填充翻譯字串。
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_XA 和 ar_XB。
提示
您可以使用這個擴充套件來開始翻譯現有或相似的語言。一旦您加入翻譯到這組件,也將會套用擴充套件。例如:您有 fr 且想加入 fr_CA 翻譯,只需要將 fr 設定來源語言,fr_CA 為目標翻譯,並將前字尾留空。
在填滿新翻譯後解除安裝擴充套件以防止 Weblate 變更複製後的翻譯。
評論中的貢獻者紀錄¶
- 附加元件 ID:
weblate.gettext.authors- 配置:
This add-on has no configuration.
- 觸發:
更新 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.
- 觸發:
每當新增或移除翻譯時,更新「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 評論佔位字元。
- 觸發:
使用 Django 內建的 makemessages 指令更新 gettext 範本。
更新 LINGUAS 檔案¶
- 附加元件 ID:
weblate.gettext.linguas- 配置:
This add-on has no configuration.
- 觸發:
當新增或移除翻譯時更新 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 用於擷取評論的標籤。
checksxgettext 檢查
針對擷取的訊息,要啟用的其他 xgettext 驗證檢查。
可用的選擇:¶ ellipsis-unicodeellipsis-unicode
space-ellipsisspace-ellipsis
quote-unicodequote-unicode
bullet-unicodebullet-unicode
keyword額外關鍵字
可選擇傳遞給 xgettext 的其他關鍵字,使用 --keyword 引數。
presetMeson 預設
內建的 xgettext 引數預設組態,與 Meson 的 gettext 整合功能相符。這個 GLib 預設組態加上了 Meson 的 gettext 輔助程式所使用的關鍵字及格式旗標選項。
可用的選擇:¶ glibGLib
- 觸發:
依照 Meson 的 gettext 慣例更新 gettext 範本。
產生 MO 檔案¶
- 附加元件 ID:
weblate.gettext.mo- 配置:
path產生的 MO 檔案路徑
如果未指定,將使用 PO 檔案的位置。
fuzzy包含需要編輯的字串
需要編輯的字串 (fuzzy) 通常無法直接被用為翻譯。
- 觸發:
每次 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.
- 觸發:
使用 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.
也參考
msgmerge
更新 POT 檔案(Sphinx)¶
在 5.17 版被加入.
- 附加元件 ID:
weblate.gettext.sphinx- 配置:
- 觸發:
使用 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 用於擷取評論的標籤。
checksxgettext 檢查
針對擷取的訊息,要啟用的其他 xgettext 驗證檢查。
可用的選擇:¶ ellipsis-unicodeellipsis-unicode
space-ellipsisspace-ellipsis
quote-unicodequote-unicode
bullet-unicodebullet-unicode
keyword額外關鍵字
可選擇傳遞給 xgettext 的其他關鍵字,使用 --keyword 引數。
input_mode輸入來源
選擇要讓 xgettext 從 glob 樣式讀取來源檔案,或是從 POTFILES/POTFILES.in 資訊清單檔案讀取。
可用的選擇:¶ patterns來源檔案形式
potfilesPOTFILES 資訊清單
languagexgettext 語言
傳遞給 xgettext 的程式語言,例如 Python 或 C。
source_patterns來源檔案形式
以換列符號分隔的儲存庫相對路徑 glob 樣式,用來指定要使用 xgettext 擷取的檔案。
potfiles_pathPOTFILES 路徑
指向 POTFILES 或 POTFILES.in 的儲存庫相對路徑。項目的解析以儲存庫根目錄為基準。若與資訊清單位於同一目錄,POTFILES.skip 會將列出的檔案排除在擷取範圍之外。
- 觸發:
使用 xgettext 針對選取的來源檔案更新 gettext 範本。
匯併 Git 提交¶
- 附加元件 ID:
weblate.git.squash- 配置:
squash提交匯併
可用的選擇:¶ all所有提交匯併為一
language每個語言
file每個檔案
author每位作者
append_trailers在將多個提交壓縮(squash)為一個提交時,將某些特定的詮釋資料(trailers)附加到最終的提交資訊中
額外資訊的列看起來類似於 RFC 822 郵件信箱標頭,位於提交訊息的其他自由格式部分的末尾,例如「Co-authored-by: …」。
commit_message提交訊息
此提交訊息將用來取代從壓縮提交組合而成的提交訊息。
- 觸發:
推送變更前先匯併 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 版被加入.
每天晚上都丟棄在 Weblate 儲存庫中所有的變動。
格式化 Java properties 檔案¶
- 附加元件 ID:
weblate.properties.sort- 配置:
case_sensitive啟用區分大小寫的字串鍵排序
- 觸發:
格式化並排序 Java properties 檔案。
將新行合併為 Unix ones。
Unicode 跳脫符號的大寫格式(如果有的話)。
替除空白行與評論。
依鍵值排序字串。
移除重複字串。
陳舊評論移除¶
設定移除評論的時間間隔。
這可以用於刪除可能變得過時的陳舊註釋。小心使用,因為陳舊的註釋不意味著失去了重要性。
陳舊建議移除¶
- 附加元件 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.
- 觸發:
更新所有翻譯檔案以符合單語言上游基底檔。未使用的字串將移除,新增加的字串將根據來源字串複製加入。
提示
如果只想刪除陳舊的翻譯鍵,那麼使用 清理翻譯檔案。
Slack Webhooks¶
在 5.12 版被加入.
根據選擇事件傳送通知到 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_urlWebhook URL
secretWebhook 金鑰
標準的 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 版被移除: 被 檔案格式參數 取代。
常見附加元件參數¶
機器翻譯引擎¶
|
阿里巴巴 |
|
Amazon 翻譯 |
|
Anthropic |
|
Apertium APy |
|
Azure AI 翻譯器 |
|
Azure OpenAI |
|
Baidu |
|
CyrTranslit |
|
DeepL |
|
Glosbe |
|
Google Cloud 翻譯進階版 |
|
Google Cloud 翻譯基本版 |
|
LTEngine |
|
LibreTranslate |
|
ModernMT |
|
MyMemory |
|
Netease Sight |
|
Ollama |
|
OpenAI |
|
SAP Translation Hub |
|
Systran |
|
Weblate |
|
Weblate 翻譯記憶 |
|
Yandex |
|
Yandex v2 |
|
Youdao Zhiyun |
|
tmserver |
檔案格式¶
|
XLIFF 1.2 附 Apple 擴充功能 |
|
App store 詮釋資料檔案 |
|
ARB 檔案 |
|
Android 字串資源 |
|
AsciiDoc 檔案 |
|
Advanced SubStation Alpha 字幕檔案 |
|
Haiku catkeys |
|
Compose Multiplatform 資源 |
|
CSV 檔案 |
|
多值 CSV 檔案 |
|
簡易 CSV 檔案 |
|
DokuWiki 文字檔案 |
|
DTD 檔案 |
|
Flat XML 檔案 |
|
Fluent 檔案 |
|
Format.JS JSON 檔案 |
|
go-i18n v1 JSON 檔案 |
|
go-i18n v2 JSON 檔案 |
|
go-i18n TOML 檔案 |
|
gotext JSON 檔案 |
|
GWT 屬性 |
|
HTML 檔案 |
|
i18next JSON 檔案 v3 |
|
i18next JSON 檔案 v4 |
|
IDML 檔案 |
|
INI 檔案 |
|
Inno Setup INI 檔案 |
|
Joomla 語言檔案 |
|
JSON 檔案 |
|
JSON 巢狀結構檔案 |
|
Laravel PHP 字串 |
|
Markdown 檔案 |
|
MDX file |
|
MediaWiki 文字檔案 |
|
@draggable/i18n 語言檔案 |
|
Mobile Kotlin 資源 |
|
Nextcloud JSON 檔案 |
|
OpenDocument 檔案 |
|
PHP 字串 |
|
XLIFF 1.2 翻譯檔案 |
|
gettext PO 檔案 |
|
gettext PO 檔案(單語) |
|
XLIFF 1.2 附 gettext 擴充功能 |
|
Java 屬性 |
|
RC 檔案 |
|
RESJSON 檔案 |
|
ResourceDictionary 檔案 |
|
.NET 資源檔案 |
|
Ruby YAML 檔案 |
|
SubRip 字幕檔案 |
|
SubStation Alpha 字幕檔案 |
|
iOS 字串 |
|
Stringsdict 檔案 |
|
MicroDVD 字幕檔案 |
|
TermBase eXchange 檔案 |
|
TOML 檔案 |
|
Qt Linguist 翻譯檔案 |
|
純文字檔案 |
|
WebExtension JSON 檔案 |
|
WixLocalization 檔案 |
|
包含佔位字串支援的 XLIFF 1.2 |
|
XLIFF 2.0 翻譯檔案 |
|
包含佔位字串支援的 XLIFF 2.0 |
|
Excel Open XML |
|
XWiki Full Page |
|
XWiki Java Properties |
|
XWiki 頁面屬性 |
|
YAML 檔案 |
變更事件¶
|
資源已更新 |
|
完成了翻譯 |
|
變更了翻譯 |
|
新增了評論 |
|
新增了建議 |
|
新增了翻譯 |
|
自動翻譯 |
|
接受了建議 |
|
還原了翻譯 |
|
上傳了翻譯 |
|
新增了原文 |
|
鎖定了組件 |
|
解除了組件鎖定 |
|
已提交變更 |
|
已推送變更 |
|
已重設儲存庫 |
|
已合併儲存庫 |
|
已 rebase 儲存庫 |
|
儲存庫合併失敗 |
|
儲存庫 rebase 失敗 |
|
解析失敗 |
|
移除了翻譯 |
|
移除了建議 |
|
取代了翻譯 |
|
儲存庫推送失敗 |
|
在清理時移除了建議 |
|
來源字串有變更 |
|
新增了字串 |
|
已變更大量狀態 |
|
已變更可見性 |
|
新增了使用者 |
|
移除了使用者 |
|
核可了翻譯 |
|
標記為需要編輯 |
|
移除了組件 |
|
移除了專案 |
|
重新命名了專案 |
|
重新命名了組件 |
|
移動了組件 |
|
有新貢獻者加入 |
|
發佈了公告 |
|
觸發了警告 |
|
新增了語言 |
|
已請求加入語言 |
|
建立了專案 |
|
建立了組件 |
|
邀請了使用者 |
|
收到儲存庫通知 |
|
上傳並取代了翻譯檔案 |
|
已變更授權 |
|
已變更貢獻者授權契約 |
|
新增了畫面擷圖 |
|
上傳了畫面擷圖 |
|
儲存庫有更新字串 |
|
已安裝附加元件 |
|
已變更附加元件配置 |
|
已解除安裝附加元件 |
|
移除了字串 |
|
移除了評論 |
|
解決了評論 |
|
更新了解釋 |
|
移除了類別 |
|
重新命名了類別 |
|
移動了類別 |
|
儲存字串失敗 |
|
儲存庫有加入字串 |
|
上傳的檔案更新了字串 |
|
上傳的檔案新增了字串 |
|
透過上傳原文更新了翻譯 |
|
完成了組件翻譯 |
|
套用了強制檢查 |
|
傳播了變更 |
|
檔案已上傳 |
|
附加標記已更新 |
|
字型已上傳 |
|
字型已變更 |
|
字型已移除 |
|
已強制同步翻譯 |
|
已強制重新掃描翻譯 |
|
擷圖已移除 |
|
標籤已移除 |
|
標籤已移除 |
|
儲存庫清理 |
|
在上傳時新增了來源字串 |
|
在儲存庫中新增了來源字串 |
|
已備份專案 |
|
已還原專案 |
|
已還原組件 |
|
還原了使用者編輯 |
|
Project setting changed |
|
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.