若需非默认位置,则以configPath输入覆写路径。
结构
# .github/resource-translator.ymlsourceLocale: en
# Provider config can be nested. Keep secrets in workflow inputs; use repo# config for non-secret defaults like region, model, formality, or category.provider: azure: categoryId: my-custom-translator-category apiVersion: "3.0" allowFallback: true
toLocales: - fr - de - esinclude: - "src/**/*.en.json" - "apps/**/*.en.resx"exclude: - "**/__tests__/**"glossary: Acme: Contoso Octocat: Octocat # keep brand names verbatim
# Translator request shape — most users can ignore these.textType: plain # plain | htmlprofanityAction: NoAction # NoAction | Marked | DeletedprofanityMarker: Asterisk # Asterisk | Tag (only when profanityAction == Marked)
# 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.*"场域参考
providerEither a provider string or a nested provider block (provider.azure, provider.aws, or provider.google). Prefer nested blocks for provider-specific settings; keep secrets in workflow inputs rather than committed config.
sourceLocale若未设,则退回sourceLocale输入。 亦转发至译者,from=<locale>短字符串不致自动识别。
toLocales或为数组,或为逗号分隔之字符串。
include / exclude球状模式以绝对路径及工作空间相对路径评估。
glossary译后之词可覆写。 词界感知(处理C++、.NET)。
categoryIdAzure Custom Translator类别——汝之行业/领域旋钮(法律、医疗、营销语气等)。 寄?category=...。
textType默认为plain。 唯资源值含真实HTML片段时方用html。
profanityAction译文中粗俗词汇之处理。
profanityMarker唯profanityAction "Marked"时方有意义。
allowFallback设false以致categoryId无目标部署时转换失败,非退回通用模型。
apiVersion譯者REST API版本。 默认为3.0。
awsFormalityAWS Translate formality setting for supported target languages.
awsBrevitySet to true to enable AWS Translate brevity mode for supported language pairs.
awsTerminologyNames / awsParallelDataNamesAWS Translate custom terminology and parallel data resource names. Either an array or comma-separated string.
googleModelGoogle Cloud Translation model, e.g. nmt or base.
googleApiEndpointOptional Google Cloud Translation API endpoint override.
googleAutoRetryOptional Google Cloud Translation automatic retry toggle. Leave unset to use the Google client default.
maxRetries瞬态HTTP响应之最大重试次数(408, 425, 429, 500, 502, 503, 504)。 默认为5。 每请求总HTTP调用为1 + maxRetries。
retryBackoffMs凡单次后退睡眠,皆为上限(毫秒)。 默认为30000。 Azure之Retry-After首,惟有之则必尊; 否则则用抖动指数回退,限于此值。
protectPlaceholders默认为true。 啟用時,{{name}}、${var}、{0}、{0:N2}、%s、%1$s及HTML等符號,於轉換前被哨兵符號取代,轉換後復原。 仅于源含占位形文字时禁用。
customPlaceholderPatterns於預設占位符集增設無分隔符之正則表達式,如自訂令牌語法之<<.+?>>。 無效正則表達式不予理會。
noTranslatePatterns球狀圖案與解析器層級鍵(如JSON附點路徑、RESX name、PO msgid、XLIFF單元id、INI/重文本鍵)相匹配。 匹配密钥自请求中弃之,传递时其源值得以保留。
changeDetectionDefaults to smart. Uses the committed state manifest to translate only changed or missing parser keys. Set to disabled or false to preserve the legacy always-translate behavior.
statePathPath to the deterministic smart change-detection state manifest. Defaults to .github/resource-translator-state.json.
装载顺序
- 动作读取工作流程中显式输入。
- 其载入
configPath之YAML配置。 - 每共用一欄位,輸入勝; 否则用YAML值。
- 合并值经验证。 枚舉無效(如
profanityAction: Mask)則動作迅速失敗且訊息清晰。
語氣與工業,簡言之
Azure AI Translator v3 API 無單一音調旋鈕。 二者合用,操控大抵相同:
- 產業/領域: 用
categoryId指向Azure Custom Translator类别,皆以己语料库训练——法律、技术、医疗、市场营销及他类。 此为语气、品牌声线及词汇之最强杠杆。 - 表文: 詞彙表可逐字锁定品牌名及产品名,
profanityAction则剔除粗俗词汇,针对年轻群体本地化。