Automation reference and cookbook

The 自动化 add-on runs declarative workflows using existing Weblate operations. This page describes the workflow structure, triggers, conditions, and actions. See Cookbook for complete examples, including 在机器翻译前应用翻译记忆库.

工作流定义

Added in version 2026.10.

参数

名称

Required

Type or allowed values

version

是

1

triggers

是

List of (object); maximum items 100; unique items

conditions

否

List of (condition); maximum items 100

actions

是

List of (action); maximum items 100

The add-on configuration offers two ways to edit a workflow, and the Editor and YAML buttons switch between them without losing unsaved changes.

Editor builds the workflow from the triggers, conditions, and actions described on this page, offering the parameters of each one as a form. It opens by default. Condition groups (和, 或, 非) and branching actions (序列, 选择) nest inside one another, so the whole workflow structure is editable there. A workflow the editor cannot show, such as one naming an action this Weblate does not have, opens in YAML instead and says so. The editor requires JavaScript.

YAML is the Workflow field itself. JSON input is also accepted. Saved workflows reopen as YAML with version, triggers, optional conditions, and actions in that order. Comments and original formatting are not retained. The API accepts the same structure as the workflow member of configuration. The JSON Schema describes this representation independently of the editor. Unknown keys are rejected.

version identifies the workflow schema version, not the Weblate release. List the events to subscribe to in triggers, conditions that must pass before any action runs in conditions, and the ordered operations in actions. Omitting conditions is equivalent to an empty list. Empty triggers allows manual execution only; empty actions performs no operations.

文字设置和表达

Action settings are literal YAML/JSON values. Only the value of an expression condition is evaluated as CEL. Queries, engine IDs, labels, and other settings do not support CEL expressions, variable substitution, or template syntax such as {{ unit.id }}. A query containing that syntax is not expanded. Use 选择 to select actions with different fixed settings. Actions select strings using their scope and optional query.

字符串作用域

Set scope on an action to choose its starting selection. component is the default and retains the existing component-wide behavior. trigger uses the unit affected by a change event; a source-unit change selects its corresponding target-language units. result:ID uses units actually changed or given new suggestions by an earlier action with that id. For an AI quality action, it uses units successfully evaluated by that action. For a select action, it uses the units selected by that action. Set settings.q to filter the selected units further. For trigger and result:ID, omitting q selects the whole scope.

For example, a translation action with id: machine and scope: trigger can be followed by a bulk edit with scope: result:machine. The second action sees only units affected by the first. Source-level edits can select the corresponding target units in a later action.

Workflows using scope: trigger can declare only change triggers. A change without a unit fails if execution reaches that action. Manual execution and preview require a change containing a unit before starting such workflows. A result:ID action fails if its referenced action did not run, for example because a branch was skipped. Preview can follow result scopes created by select actions when their selections are known. Other result scopes are conditional because earlier actions have not run.

Selections are kept only while the run is active. The activity log records affected counts and scoped unit counts (before the q filter), but does not store the full unit ID lists.

执行上下文

CEL conditions can access the following fields. Context is captured when the run is scheduled, and only results changes between actions. In particular, unit.state is a snapshot; use matching_strings for current database state. Timestamps are strings, not CEL timestamp objects.

上下文字段

字段

类型

含义

component.id

整数

目标部件 ID;始终存在。

component.slug

字符串

目标部件标识串。

component.project

字符串

项目标识串,非项目对象。

component.category

string or null

类别标识串;未分类部件值为空。

language.id

整数

Event language ID, when language is available.

language.code

字符串

Event language code, when language is available.

unit.id

整数

Event unit ID, when unit is available.

unit.state

整数

Captured string state; see 字符串状态.

unit.source

字符串

原文文本,缩短到 4096 个字符串。

unit.target

字符串

Target text, truncated to 4,096 characters.

change.id

整数

Triggering change ID, when change is available.

change.action

整数

Numeric ActionEvents value, not the lowercase event name.

change.timestamp

字符串

Change timestamp in ISO 8601 format with a timezone offset.

actor.id

整数

Recorded actor ID, when actor is available.

actor.username

字符串

Recorded actor username.

trigger.name

字符串

Trigger identifier such as change, daily, or manual.

trigger.timestamp

字符串

Change timestamp, or scheduling time for other triggers; ISO 8601 with a timezone offset.

trigger.revision

string or null

Component local revision recorded when scheduled; null if unavailable.

trigger.unit_ids

list of integers or null

Currently a one-element list when the change references a unit; otherwise null.

trigger.source_unit_ids

list of integers or null

Source-unit IDs corresponding to trigger.unit_ids; otherwise null.

results

对象

Initially empty; maps action IDs to successful operation outputs.

Availability depends on the trigger:

  • change supplies change. It supplies unit and language only when the change references them, and actor from the change's user or, if absent, its author. Any of those optional objects can be null.

  • manual supplies actor when initiated by a user through the UI or API. Other manual entry points may have no actor. change, unit, and language are null.

  • daily, component_update, post_update, post_commit, and post_push have null actor, change, unit, and language.

  • A preview with a change ID uses that change's context and trigger.name of change. Without one, it uses manual context.

When an object is null, its child fields cannot be accessed directly. For example, use unit != null && unit.state == 10 or language != null && language.code == "de". Prefer the typed unit_state, language, and change_action conditions when possible; they handle missing context and event-name conversion for you. See 原文更改后翻译.

执行身份和权限

The usual add-on management permission authorizes configuration, preview, and manual execution. actor records who caused an event; it does not select the account or permissions used to perform actions. Changing a condition on actor only determines whether the workflow runs.

Operations execute with the add-on's authority within its configured scope, not with the triggering user's individual translation permissions. Automatic translation receives the Automation add-on bot as its execution user and does not apply per-user operation permission checks. Reused translations can retain their original author attribution. Bulk editing also records the Automation add-on bot as its execution user. The activity context retains the actor separately from translation change attribution.

Author-filtered conditions, selections, and AI-evaluation searches use the same administrative scope in previews and execution. They do not depend on Guest permissions or the configuring or triggering user's contributor identity access.

Changes made during execution record an automation origin with the installed add-on ID and execution-log ID in 翻译历史记录. This also covers background tasks and repository processing started by the automation. The identifiers remain available after an add-on or its execution log is removed; workflow settings are not copied into change history.

Project, category, and site-wide automations include compatible restricted components in their configured scope. Automatic-translation actions can use eligible restricted source components outside the configuring administrator's direct access. Preview uses the same administrative scope and can inspect the selected component and optional change context. Grant add-on management permission only to users trusted with this complete scope. Changing or disabling the configuring user's account does not revoke a saved workflow.

Before a queued run executes, Weblate checks that the add-on is still valid and the component still belongs to its scope. The queued definition and event context are snapshots: editing the workflow after scheduling does not change that run. Operation settings are validated again against the target component at execution.

测试和执行

Save the workflow before using the separate Run add-on form. Inherited automations require a component ID; each submission targets one component. A change ID supplies event context and must belong to that component and match a configured change subscription. Workflows with only change triggers require a change ID. Workflows using scope: trigger also require the change to contain a string.

Preview without changes is checked by default. Select Run now with it checked to inspect conditions and planned actions. Preview neither calls translation services nor changes strings. Conditions that depend on unexecuted action results or changed strings are marked unknown, and their branches are shown as conditional. Clear the checkbox to schedule real execution with the same context and saved workflow. Validation errors preserve the checkbox selection; reopening the page enables preview again.

Without a change ID, execution uses manual context with no language, string, or change. With a change ID, context uses that change's event, actor, and timestamp, and the string's current state, not a reconstruction of its historical state. The requesting administrator is recorded separately in the activity log. Component-scoped actions still operate across the component; supplying a change does not implicitly restrict their selection. Use scope: trigger to select strings affected by that change.

The 附加组件 provides equivalent preview and run operations.

Runs use ordinary Celery tasks and existing operation locks. Separate runs may overlap; there are no execution modes or parallel action blocks. The activity log records the definition, context, conditions, actions, and failures. An error stops later actions without rolling back completed work. Runs are not automatically replayed; after a worker is forcibly terminated, a pending log can remain and must be inspected before manually starting another run. Changes originating from an automation, including follow-up tasks, do not start other automation runs.

验证和限制

Workflows must contain JSON-compatible values with string mapping keys. YAML aliases, explicit tags, duplicate mapping keys, non-finite numbers, and native YAML date/timestamp values are rejected. Quote a date if a string is intended. Unknown fields are rejected, and action IDs must be unique across the entire workflow, including mutually exclusive branches. Missing required fields and wrong value types are errors; for example, state must be an integer, not "10". Nested mappings and lists also have a structural depth limit of 32.

Generated parameter tables show list limits, uniqueness requirements, numeric bounds, and string patterns from the schema. Item constraints in parentheses apply to each list element. The workflow-wide node and nesting limits below still apply even when each individual list is within its limit.

Definitions are limited to 64 KiB both as submitted and as ASCII-escaped JSON after operation defaults are applied, 100 action/condition nodes, and eight nesting levels. CEL expressions are limited to 4,096 characters and evaluated in a helper process with two seconds of CPU time and five seconds of wall time per invocation. The helper also limits virtual address space to 512 MiB except on macOS, where no memory cap is enforced. The helper fails closed if a required operating-system resource limit cannot be applied. The pinned CEL runtime provides native wheels; Linux installations require a supported glibc platform. No runtime settings or separate service are required. Use 编写附加组件 for unrestricted custom Python logic on self-hosted installations.

触发器

Each trigger is an object in the workflow's triggers list. An instance can subscribe to multiple triggers. Manual execution is always available, even when manual is absent from the list.

每天

参数

名称

Required

Type or allowed values

trigger

是

"daily"

Runs on 每天, respecting BACKGROUND_TASKS.

component_update

参数

名称

Required

Type or allowed values

trigger

是

"component_update"

Runs on 部件更新, after Weblate updates the component.

post_update

参数

名称

Required

Type or allowed values

trigger

是

"post_update"

拉取新更改 时运行。

post_commit

参数

名称

Required

Type or allowed values

trigger

是

"post_commit"

提交更改后 时运行。

post_push

参数

名称

Required

Type or allowed values

trigger

是

"post_push"

推送仓库到上游后 时运行。

manual

参数

名称

Required

Type or allowed values

trigger

是

"manual"

Runs when an administrator selects Run now, or requests manual execution through the 附加组件.

更改

参数

名称

Required

Type or allowed values

trigger

是

"change"

events

是

List of (Event name from 已选中更改事件); minimum items 1; unique items

Subscribes to the identifiers listed in 已选中更改事件, for example translation_changed, translation_added, source_string_changed, or source_string_added_in_the_repository. translation_changed covers edits to existing translations; translation_added covers previously untranslated strings translated by a user. Uploads and automatic translation have separate events. Legacy internal names such as change and source_change remain accepted and are converted to documented identifiers when edited or saved. These identifiers distinguish edits in Weblate from uploads and repository imports; a source-edit event alone does not cover all three. Only changes associated with a component can start a run.

条件

Every condition in a list must pass. A false workflow-level condition skips the run. Conditions can also select a 选择 branch. Conditions concerning unavailable language, unit, or change context return false. An empty condition list passes.

表达式

参数

名称

Required

Type or allowed values

condition

是

"expression"

value

是

string; maximum length 4096

Evaluates value as CEL and requires a boolean result. CEL supports arithmetic, comparisons, standard functions, and comprehensions, but cannot call Python or access the database, network, or filesystem. Expressions can use the captured execution context and outputs of earlier actions, for example results.machine.updated > 0. Missing fields or expression errors fail the run.

component_category

参数

名称

Required

Type or allowed values

condition

是

"component_category"

value

是

string; maximum length 4096

Compares the triggering component's category slug with value.

语言

参数

名称

Required

Type or allowed values

condition

是

"language"

value

是

string; maximum length 4096

Compares the event's language code with value. This tests the trigger context; it does not restrict subsequent actions to that language. Use an action's search query to restrict the strings it processes.

matching_strings

参数

名称

Required

Type or allowed values

condition

是

"matching_strings"

value

是

string; maximum length 2048

Passes when the component currently contains at least one string matching the search query in value. The query runs when the condition is evaluated, so it can observe changes made by earlier actions.

change_action

参数

名称

Required

Type or allowed values

condition

是

"change_action"

value

是

Event name from 已选中更改事件

Compares the triggering change's action with value. Use the lowercase event name, as for 更改.

unit_state

参数

名称

Required

Type or allowed values

condition

是

"unit_state"

value

是

0, 10, 11, 12, 20, 30, 100

Compares the triggering unit's captured state with the integer value. It uses the event snapshot, not a new query of the unit after earlier actions.

和

参数

名称

Required

Type or allowed values

condition

是

"and"

conditions

是

List of (condition); maximum items 100

Passes when every nested condition passes. Evaluation stops at the first false condition. An empty list passes.

或

参数

名称

Required

Type or allowed values

condition

是

"or"

conditions

是

List of (condition); maximum items 100

Passes when any nested condition passes. Evaluation stops at the first true condition. An empty list does not pass.

非

参数

名称

Required

Type or allowed values

condition

是

"not"

conditions

是

List of (condition); maximum items 100

Negates exactly one nested condition. Empty lists and lists containing multiple conditions are invalid.

操作

Actions run in list order. Each operation and its batched checks finish before the next action starts. Actions target the component; use 搜索字符串 queries to narrow them. Queries are evaluated when each action executes.

Optional unique action IDs expose outputs as results.<id>. An ID starts with a lowercase letter and contains up to 64 lowercase letters, digits, or underscores. After a successful operation, its output is stored in the activity log and, when it has an ID, in results.<id> for later CEL conditions. For example, results.memory.updated > 0 tests whether the memory action reported updates. Outputs belong to the current run and are not shared with other runs.

Skipped and failed operations do not create result entries. Preview creates entries for select actions when it can determine their selections; other previewed operations do not. If an action might be skipped, guard access with a presence check such as has(results.memory) && results.memory.updated > 0. A failed operation records an error in the trace and stops later actions; its partial changes are not rolled back. Actions without IDs still record their outputs in the activity log.

The YAML examples below are items to place in the workflow's actions list. The cookbook provides complete workflow definitions.

Settings and queries are validated against the target component before execution. For inherited workflows, labels must exist in each target project and selected engines must be enabled there.

选择字符串

Added in version 2026.11.

参数

名称

Required

Type or allowed values

action

是

"weblate.select"

id

否

string; pattern ^[a-z][a-z0-9_]{0,63}$

scope

否

"component", "trigger", string; pattern ^result:[a-z][a-z0-9_]{0,63}$

settings

是

对象

settings.q

否

string; maximum length 2048

结果字段

名称

Required

Type or allowed values

component

是

整数

selected

是

integer; minimum 0

Use weblate.select to name a set of strings for later result:ID actions. It only reads strings. In component scope, q is required; in trigger or result scope, omit q to keep the current selection. q uses the usual 搜索字符串 syntax. The result contains the selected count, while the unit IDs remain available only during the run.

For example, select untranslated German strings from a change event before running automatic translation:

- action: weblate.select
  id: changed_german
  scope: trigger
  settings:
    q: "language:de AND state:<translated"
- action: weblate.automatic_translation
  scope: result:changed_german
  settings:
    auto_source: mt
    engines: [openai]
    mode: translate

自动翻译

Added in version 2026.10.

参数

名称

Required

Type or allowed values

action

是

"weblate.automatic_translation"

id

否

string; pattern ^[a-z][a-z0-9_]{0,63}$

scope

否

"component", "trigger", string; pattern ^result:[a-z][a-z0-9_]{0,63}$

settings

是

对象

settings.mode

否

"suggest", "translate", "fuzzy", "approved"

settings.q

否

string; maximum length 2048

settings.auto_source

否

"others", "mt"

settings.component

否

integer or null; minimum 1

settings.engines

否

List of (string; maximum length 4096); maximum items 100

settings.threshold

否

integer; minimum 1; maximum 100

结果字段

名称

Required

Type or allowed values

component

是

整数

updated

是

整数

message

是

字符串

warnings

是

List of (string; maximum length 1024); maximum items 20

warnings_omitted

是

integer; minimum 0

Runs 自动翻译 synchronously. auto_source: others reuses translations from other components, optionally restricted by the source component ID. auto_source: mt uses the service IDs in engines; translation memory and AI services use the same mechanism as other providers.

Defaults are auto_source: others, mode: suggest, q: state:<translated, threshold: 80, no source component restriction, and an empty engine list. For a scoped action, omitted q selects its whole scope instead. Provide configured engine IDs when selecting mt.

mode selects suggestions (suggest), translations (translate), strings needing editing (fuzzy), or approved translations (approved). Approval follows each language's effective review settings. threshold is a minimum score from 1 to 100 for services; each service has its own maximum score.

示例

Apply local translation memory matches scoring at least 95 to strings still needing translation. Enable Weblate 翻译记忆库 in the target project before running this action.

- action: weblate.automatic_translation
  id: memory
  settings:
    auto_source: mt
    engines: [weblate-translation-memory]
    threshold: 95
    mode: translate
    q: "state:<translated"

查看 在机器翻译前应用翻译记忆库 用远程翻译服务照着该流程做。

输出

component (整数)

ID of the component processed, not the optional source component.

updated (integer)

Number of translation updates or new suggestions reported across the component's languages. In suggestion mode, this counts newly created suggestions, not strings whose translation state changed. A translation that exceeds the string's maximum length can also become a suggestion, even in translation mode. Zero means the operation reported no updates; it is not an error by itself.

message (字符串)

Human-readable completion summary in English. Use updated for conditions instead of parsing this message.

warnings (字符串列表)

Warnings reported by automatic translation, or an empty list when none were reported. At most 20 messages are retained, each truncated to 1,024 characters. A successful action can still have warnings; inspect them when fewer strings were translated than expected.

warnings_omitted (integer)

Number of warning messages omitted beyond the first 20. This does not count characters removed from retained messages.

For example, a successful run might record:

{
  "component": 42,
  "updated": 3,
  "message": "Automatic translation completed, 3 strings were updated.",
  "warnings": [],
  "warnings_omitted": 0
}

A later condition can access these fields through results.memory, for example results.memory.updated > 0 && size(results.memory.warnings) == 0.

AI 质量评估

Added in version 2026.10.

参数

名称

Required

Type or allowed values

action

是

"weblate.ai_quality"

id

否

string; pattern ^[a-z][a-z0-9_]{0,63}$

scope

否

"component", "trigger", string; pattern ^result:[a-z][a-z0-9_]{0,63}$

settings

是

对象

settings.service

否

string; maximum length 4096

settings.q

否

string; maximum length 2048

结果字段

名称

Required

Type or allowed values

component

是

整数

evaluated

是

integer; minimum 0

Evaluates existing target translations synchronously using the effective AI quality evaluation add-on. Its configured service is used automatically. An optional service asserts that the effective add-on uses that service; a mismatch stops the workflow. The optional q filters the action's scope further; the add-on's own query and eligibility rules still apply. Empty scoped selections make no provider requests.

Each evaluated string is available to a later result:ID action when this action has an id. evaluated counts those strings; unit IDs are kept only during the run. The action stops later steps if a request fails, is rate limited, or its response is discarded because the string changed during evaluation. Earlier successful batches can retain their findings, so a later run may reevaluate them. See 批准前评估 AI 译文 for a complete translation and review workflow.

批量编辑

Added in version 2026.10.

参数

名称

Required

Type or allowed values

action

是

"weblate.bulk_edit"

id

否

string; pattern ^[a-z][a-z0-9_]{0,63}$

scope

否

"component", "trigger", string; pattern ^result:[a-z][a-z0-9_]{0,63}$

settings

是

对象

settings.q

否

string; maximum length 2048

settings.state

否

整数

settings.search

否

string; maximum length 4096

settings.replacement

否

string; maximum length 4096

settings.search_type

否

"text", "regex"

settings.add_flags

否

string; maximum length 4096

settings.remove_flags

否

string; maximum length 4096

settings.add_translation_flags

否

string; maximum length 4096

settings.remove_translation_flags

否

string; maximum length 4096

settings.add_labels

否

List of (string; maximum length 4096); maximum items 100

settings.remove_labels

否

List of (string; maximum length 4096); maximum items 100

结果字段

名称

Required

Type or allowed values

component

是

整数

updated

是

整数

Uses the same operation as 批量编辑. For component scope, q is required and selects strings using 搜索字符串. For trigger and result scopes, q is optional and filters the selected strings. state sets an integer string state, or leaves it unchanged with -1 (the default).

文字替换

search and replacement have the same meaning as in 批量编辑. search_type is text (the default) or regex. Empty search disables replacement; empty replacement removes matching text. Regex replacements use Python capture references such as \g<1> or \g<name>. Each plural form is processed separately, and whitespace is preserved.

例如,这个操作交换两个捕捉到的单词:

- action: weblate.bulk_edit
  settings:
    q: "language:cs"
    search_type: regex
    search: '(Hello), (world)'
    replacement: '\g<2>, \g<1>'

The query or action scope selects strings for all operations. Adding replacement does not narrow accompanying state, flag, or label changes. Set state: 0 to clear translations, including every plural form; source strings are excluded. Clearing cannot be combined with replacement.

The visual editor offers the same search-type choices, replacement fields, and Empty state as the add-on. Automated runs process the full eligible scope without interactive preview. Invalid patterns or replacement references are rejected; a regex timeout fails the operation and rolls back changes to the current component. Earlier component changes in a project-wide add-on run remain applied.

Regex replacement uses the fixed 批量编辑 resource limits. Workflow validation shares one helper across action settings; execution shares the regex budget across bulk-edit actions. Synchronously processed components share the budget, while separately queued tasks have independent budgets. Pattern compilation and template validation also run in the helper. A resource failure fails the operation rather than skipping the affected string or retrying with a fresh budget. On macOS, native regex allocations are not protected by a hard address-space limit.

字符串状态

状态值

值

含义

Accepted as a bulk-edit target

-1

保持不变

Yes; default, not an actual unit state

0

空白

是;清除翻译文本,跳过源字符串

10

需要编辑

是

11

需要编辑(需要重写)

是

12

需要编辑(需要检查)

是

20

已翻译

是

30

已核准

是

100

只读

否

The unit_state condition accepts actual unit states, including 0 and 100, but not -1. Bulk editing only changes eligible editable strings; selecting a read-only string does not make it editable.

标记和标签

Flag settings are strings containing flags to add or remove. Label settings are lists of label names. Flag defaults are empty strings and label defaults are empty lists. Source flags and labels affect all languages, just as with the bulk-edit add-on; translation flags affect the matching translations, excluding source strings. Removing a translation flag removes its local setting; inherited flags remain in effect.

Use comma-separated flags, with colon-separated parameters, for example add_translation_flags: "max-length:100, check-glossary". To remove a parameterized flag, specify its name, for example remove_translation_flags: "max-length". See 使用标记定制行为 for quoting rules and 质量检查 for available checks. Labels use YAML/JSON lists of existing project label names, for example add_labels: [needs-attention]; this does not create a label.

示例

Mark currently translated German strings as needing editing, leaving other languages and approved strings outside the query unchanged:

- action: weblate.bulk_edit
  id: marked_for_edit
  settings:
    q: "language:de AND state:translated"
    state: 10

See Run an action only when a translation pass updates strings for a conditional bulk-edit example.

输出

component (整数)

已处理部件的 ID。

updated (integer)

Count reported by the bulk-edit operation. State changes, changes to source flags or labels, and changes to translation flags contribute separately. When an action combines these operations, the same string can contribute more than once; this is not a count of distinct affected strings. Source flag and label changes are counted per source string, rather than once per language. Zero means the operation made no changes.

For example, an action that only changes the states of three strings returns:

{"component": 42, "updated": 3}

A later condition can test results.marked_for_edit.updated > 0. This output does not contain unit IDs or a list of the changed strings. A later action must select its strings with its own query.

序列

Added in version 2026.10.

参数

名称

Required

Type or allowed values

sequence

是

List of (action); maximum items 100

Groups an ordered list of actions. A sequence finishes before the next sibling action starts. It can contain operations, further sequences, and 选择 blocks. It does not introduce parallel execution.

示例

Group two translation passes: reuse other components first, then apply local translation memory to strings still needing translation.

- sequence:
    - action: weblate.automatic_translation
      id: reused
      settings:
        auto_source: others
        mode: translate
        q: "state:<translated"
    - action: weblate.automatic_translation
      id: memory
      settings:
        auto_source: mt
        engines: [weblate-translation-memory]
        threshold: 95
        mode: translate
        q: "state:<translated"

输出

A sequence has no output object and does not accept an id. Its successful child actions expose their individual outputs in the shared results object, including to subsequent children and actions outside the sequence. In this example, those entries are results.reused and results.memory; there is no combined update count. A failing child stops the remaining actions.

选择

Added in version 2026.10.

参数

名称

Required

Type or allowed values

choose

是

List of (object); maximum items 100

choose[].conditions

是

List of (condition); maximum items 100

choose[].sequence

是

List of (action); maximum items 100

default

否

List of (action); maximum items 100

Evaluates branches in order and executes the first branch whose conditions all pass. Each branch requires both conditions and sequence. Later branches are skipped after a match, even if the matching sequence is empty.

If no branch matches, default runs. Omitting default is equivalent to an empty action list.

示例

For components in the frontend category, mark translated German strings as needing editing. Other components take the empty default branch.

- choose:
    - conditions:
        - condition: component_category
          value: frontend
      sequence:
        - action: weblate.bulk_edit
          id: frontend_edit
          settings:
            q: "language:de AND state:translated"
            state: 10
  default: []

See Run an action only when a translation pass updates strings for a branch that uses an earlier action's output instead of the component category.

输出

A choose block has no output object and does not accept an id. Only successful operations in the selected branch or default branch create result entries. Branch conditions and skipped actions are recorded in the activity trace. In this example, results.frontend_edit exists only if the category matches and the bulk edit succeeds. A later condition can safely check has(results.frontend_edit) && results.frontend_edit.updated > 0. Preview records planned or conditional actions, without creating their outputs.

Cookbook

在机器翻译前应用翻译记忆库

Use separate automatic translation actions to give one source priority over another. This example first applies local translation memory matches scoring at least 95, then asks DeepL to translate only strings still needing translation.

Enable Weblate 翻译记忆库 and configure DeepL in the target project's 翻译服务. Install the Automation add-on and enter this workflow:

version: 1
triggers:
  - trigger: component_update
  - trigger: daily
actions:
  - action: weblate.automatic_translation
    id: memory
    settings:
      auto_source: mt
      engines: [weblate-translation-memory]
      threshold: 95
      mode: translate
      q: "state:<translated"
  - action: weblate.automatic_translation
    id: machine
    settings:
      auto_source: mt
      engines: [deepl]
      threshold: 80
      mode: translate
      q: "state:<translated"

The first action finishes before the second action selects its strings. Both use mode: translate, so a successful first-pass translation no longer matches state:<translated and is not sent to DeepL by the second action. Existing translated or approved strings are excluded from both passes. Untranslated strings and strings needing editing are eligible; use state:empty in both actions if only untranslated strings should be processed.

Each threshold applies only to its action. Set the memory threshold to 100 to accept only exact matches, or lower it to accept less similar matches before trying the remote service. Machine translation scores are service-specific: choose a threshold no higher than the service's documented maximum score. Replace deepl with another configured service ID to use a different provider, including an AI service.

Keep one engine per action when the order matters. Putting both IDs in one engines list uses the existing 机器翻译和翻译记忆库服务的优先级, not the list order. To try additional providers, append another action with its own engine, threshold, and the same query. To reuse translations from other Weblate components first, prepend an action using auto_source: others instead of auto_source: mt and omit engines.

Changing a pass to mode: suggest leaves the string state unchanged; mode: fuzzy leaves it needing editing. Neither excludes its results from a later state:<translated pass. Keep mode: translate when the intention is to retain each successful pass's translations.

Use Preview without changes to validate the workflow before using Run now. Preview does not call translation services or predict their results. After a real run, inspect the activity log for each action's updated count and warnings. A service failure that stops the workflow is recorded as an error; later actions do not run.

Remove or disable overlapping Automatic translation add-ons when replacing them with this workflow. Ordering applies within a single automation run; separate add-ons and concurrent runs can still overlap. The daily trigger respects BACKGROUND_TASKS. Use triggers: [] for manual execution only.

批准前评估 AI 译文

This workflow runs after repository component updates or source edits in Weblate. It applies translation memory first, translates remaining strings with OpenAI, and evaluates only strings changed by the OpenAI action. Clean strings are approved; strings with AI quality findings are marked as needing checking. Configure the translation memory and OpenAI services in the target project. Install the AI 质量评估 add-on with OpenAI as its evaluation service and its query including translated strings.

version: 1
triggers:
  - trigger: component_update
  - trigger: change
    events: [source_string_changed]
actions:
  - action: weblate.automatic_translation
    id: memory
    settings:
      auto_source: mt
      engines: [weblate-translation-memory]
      threshold: 95
      mode: translate
      q: "state:<translated"
  - action: weblate.automatic_translation
    id: machine
    settings:
      auto_source: mt
      engines: [openai]
      mode: translate
      q: "state:<translated"
  - action: weblate.ai_quality
    id: quality
    scope: result:machine
    settings: {}
  - action: weblate.bulk_edit
    scope: result:quality
    settings:
      q: "NOT (check:ai_accuracy OR check:ai_fluency OR check:ai_terminology OR check:ai_style OR check:ai_formatting)"
      state: 30
  - action: weblate.bulk_edit
    scope: result:quality
    settings:
      q: "check:ai_accuracy OR check:ai_fluency OR check:ai_terminology OR check:ai_style OR check:ai_formatting"
      state: 12

The quality action uses the intersection of its scope, the add-on query, and its optional settings.q. It stops the workflow if evaluation fails or skips any batch, so incomplete results never reach the approval action. Its result scope contains only units successfully evaluated in this run. State 12 is Needs editing (Needs checking); reviewers can inspect the findings and revise those translations. The five check:ai_* filters select non-dismissed findings. Disable the add-on's evaluation frequency and its change and update triggers if only this workflow should initiate evaluation.

Run an action only when a translation pass updates strings

Action IDs make outputs available to later conditions. For example, append the following item to the previous workflow's actions list to mark translations from the component as needing editing when the machine translation pass updated at least one string:

- choose:
    - conditions:
        - condition: expression
          value: results.machine.updated > 0
      sequence:
        - action: weblate.bulk_edit
          settings:
            q: "state:translated"
            state: 10
  default: []

The bulk-edit query selects all currently translated strings in the component, including translations that existed before the run and memory matches. It does not select only the strings updated by machine. Narrow the query to the intended strings before using this example. String state 10 means needing editing; it does not approve or request review of translations.

choose executes only the first branch whose conditions pass. Here, the empty default performs no action when the translation pass updated no strings. During preview, the condition is unknown because machine has not executed.

原文更改后翻译

This complete workflow listens for source edits in Weblate and new source strings from the repository. It runs only for categorized components matching either frontend or backend, and only when the change includes a nonempty unit. The action reuses other components' translations for German strings needing translation.

version: 1
triggers:
  - trigger: change
    events: [source_string_changed, source_string_added_in_the_repository]
conditions:
  - condition: and
    conditions:
      - condition: or
        conditions:
          - condition: component_category
            value: frontend
          - condition: component_category
            value: backend
      - condition: expression
        value: unit != null && unit.source != ""
actions:
  - action: weblate.automatic_translation
    id: reused
    settings:
      auto_source: others
      mode: translate
      q: "language:de AND state:<translated"

The null guard makes automatic changes without a unit safely skip the workflow. To run or preview this change-only workflow, supply a matching change ID belonging to the target component. Leave Preview without changes checked to inspect the event-driven path without changing strings.

The action's query targets all matching German strings in the component, not only the unit from the triggering change. trigger.unit_ids provides context for conditions; it is not automatically applied to operations and cannot be interpolated into q. The listed events do not cover every kind of source update; select additional 已选中更改事件 if the workflow should also respond to uploads or other changes.