如果你需要非預設位置,可以用 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[] | 球狀模式會以絕對路徑與工作空間相對路徑進行評估。 |
glossary | map<string,string> | 翻譯後的術語會覆蓋。字邊界感知(handles 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 | 任何單次退避睡眠都要用 cap(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刪除髒話。