如果需要非默认位置,则使用 configPath 输入覆盖路径。
图式
# .github/resource-translator.ymlsourceLocale: entoLocales: - fr - de - esinclude: - "src/**/*.en.json" - "apps/**/*.en.resx"exclude: - "**/__tests__/**"glossary: Acme: Contoso Octocat: Octocat # keep brand names verbatim
# Domain / industry — uses an Azure Custom Translator category trained on# your tone and vocabulary. Leave unset for the general model.categoryId: my-custom-translator-category
# Translator request shape — most users can ignore these.textType: plain # plain | htmlprofanityAction: NoAction # NoAction | Marked | DeletedprofanityMarker: Asterisk # Asterisk | Tag (only when profanityAction == Marked)allowFallback: true # false fails when the categoryId has no deployment
apiVersion: "3.0"
# Resilience — Translator returns 429 under load. Defaults are usually# fine; tune only if your runs are large enough to hit them.maxRetries: 5retryBackoffMs: 30000 # cap on any single backoff sleep (ms)
# Placeholder protection. ON by default — wraps tokens like {{name}},# {0}, %s, ${var} into sentinels before translation and restores them# on the way back. Set false only when source intentionally contains# placeholder-shaped literals.protectPlaceholders: truecustomPlaceholderPatterns: - "<<.+?>>" # any extra token syntax you use
# Per-key opt-out. Keys matching any glob are dropped from the request# and pass through with the source value preserved.noTranslatePatterns: - "errors.code.*" - "brands.*"现场参考
| 场 | 类型 | 笔记 |
|---|---|---|
sourceLocale | string | 如果未设置,则回退到sourceLocale输入。 也作为from=<locale>转发给 Translator,这样短字符串就不会自动检测到。 |
toLocales | string[] | 数组或逗号分隔的字符串。 |
include / exclude | string[] | 根据绝对路径和工作空间相对路径评估的 Glob 模式。 |
glossary | map<string,string> | 译后术语覆盖。 词界意识(处理C++、.NET)。 |
categoryId | string | Azure Custom Translator 类别 — 您的行业/领域旋钮(法律、医疗、营销语气等)。 送为?category=...。 |
textType | "plain" | "html" | 默认为 plain。 只有当资源值包含真实的 HTML 片段时,才使用 html。 |
profanityAction | "NoAction" | "Marked" | "Deleted" | 如何处理翻译输出中的亵渎术语。 |
profanityMarker | "Asterisk" | "Tag" | 只有当profanityAction "Marked"时才有意义。 |
allowFallback | boolean | 设置为 false,当您的categoryId没有针对目标语言环境的部署时,翻译失败,而不是回退到通用模型。 |
apiVersion | string | Translator REST API 版本。 默认为 3.0。 |
maxRetries | integer | 瞬态 HTTP 响应的最大重试次数 (408, 425, 429, 500, 502, 503, 504)。 默认为 5。 每个请求的 HTTP 调用总数为 1 + maxRetries。 |
retryBackoffMs | integer | 任何一次退避睡眠的上限 (ms)。 默认为 30000。 Azure 的 Retry-After 标头在存在时完全受到尊重; 否则使用抖动指数退避,以此值为上限。 |
protectPlaceholders | boolean | 默认为 true。 启用时,{{name}}、${var}、{0}、{0:N2}、%s、%1$s 和 HTML 实体等令牌在翻译前被 sentinel 令牌替换,然后恢复。 只有当源故意包含占位符形状的文字时,才禁用。 |
customPlaceholderPatterns | string[] | 额外的正则表达式模式(无分隔符)添加到默认占位符集中,例如自定义标记语法的<<.+?>>。 无效的正则表达式将被忽略。 |
noTranslatePatterns | string[] | Glob 模式与解析器级键(JSON 虚线路径、RESX name、PO msgid、XLIFF 单位 id、INI/restext 键)匹配。 匹配的键从请求中删除并传递,并保留其源值。 |
装车顺序
- 该操作从工作流中读取显式输入。
- 它从
configPath加载 YAML 配置。 - 对于每个共享字段,输入获胜; 否则使用 YAML 值。
- 合并的值是验证的。 无效的枚举(例如
profanityAction: Mask)会导致操作快速失败,并显示清晰的消息。
语气和工业,简单来说
Azure AI Translator v3 API 没有一个音调旋钮。 两种设置相结合,可以为您提供大部分相同的控制:
- 行业/领域: 使用
categoryId指向在您自己的语料库上训练的 Azure Custom Translator类别——法律、技术、医疗、营销或其他任何内容。 这是语气、品牌声音和词汇的最强杠杆。 - 表面文本: 使用词汇表逐字锁定品牌名称和产品术语,在针对年轻受众进行本地化时,使用
profanityAction擦去亵渎术语。