如果你需要非默认位置,可以用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>,这样短字符串就不会被自动检测。 |
toLocales | string[] | 可以是数组,也可以是逗号分隔字符串。 |
include / exclude | string[] | 球状模式对绝对路径和工作空间路径进行评估。 |
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 | 翻译器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等代币在翻译前被哨兵代币替换,翻译后恢复。仅在源代码有意包含占位符形文字时禁用。 |
customPlaceholderPatterns | string[] | 在默认占位符集中添加了额外的正则表达式模式(无分隔符),例如用于自定义令牌语法的<<.+?>>。无效的正则表达式被忽略。 |
noTranslatePatterns | string[] | 球状模式与解析器级别的键匹配(JSON点线路径、RESX name、PO msgid、XLIFF单元id、INI/restext键)。匹配的键会从请求中丢弃,并保留其源值通过。 |
装载顺序
- 该动作读取工作流程中的显式输入。
- 它会从
configPath加载YAML配置。 - 每共享一个字段,输入获胜;否则使用YAML值。
- 合并后的数值会被验证。无效枚举(例如
profanityAction: Mask)会导致动作快速失败且消息清晰。
简单来说,就是语气和工业
Azure AI 翻译器 v3 API 没有单一音调旋钮。两个设置组合起来,能让你获得大部分相同的控制:
- 行业 / 领域: 用
categoryId指向用你自己语料库训练的Azure的Custom Translator类别——法律、技术、医疗、市场营销或其他任何领域。这是影响语气、品牌声音和词汇的最有力杠杆。 - 表层文字: 用词汇表逐字锁定品牌名和产品术语,并在针对年轻受众的本地化时用
profanityAction去除脏话。