You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过/TranslateArray排除翻译文本?微软翻译API批量翻译问题

Fixing "notranslate" Issue in Microsoft Translator API's TranslateArray

Hey there, I’ve run into exactly this problem before! The single /Translate API plays nice with the <div class="notranslate"> tag, but the batch /TranslateArray API needs a slightly different approach to preserve untranslatable content like @handles or hashtags. Here are two reliable solutions I’ve used successfully:

1. Use Custom Terminology to Lock in Untranslatable Content

This method is perfect if you have a set of recurring terms you never want translated:

  • First, create a custom terminology list in the Azure Translator service. Add every @handle, hashtag, or static phrase you need to keep, setting both the source and target language versions to the exact same text (e.g., source: @TomWoolway, target: @TomWoolway).
  • When calling TranslateArray, include the CustomCategory parameter in your request, pointing to the ID of your custom terminology list.
  • The API will automatically match these terms in your batch texts and return them unmodified, no HTML tags needed.

2. Use TextType=html with <span class="notranslate">

If you prefer using inline tags (similar to the single API), you just need to adjust the tag type and explicitly set the text format:

  • Swap out <div class="notranslate"> for <span class="notranslate">—divs can cause parsing issues in batch requests since they’re block-level elements.
  • In your TranslateArray request, set the textType parameter to html (the default is plain, which ignores all HTML tags).
  • Example JSON request body:
{
  "inputs": [
    {
      "Text": "Hey <span class=\"notranslate\">@TomWoolway</span>, have you seen this <span class=\"notranslate\">#APIProTip</span>?"
    },
    {
      "Text": "Don't forget to follow <span class=\"notranslate\">@AzureTranslator</span> for updates!"
    }
  ],
  "to": "es",
  "textType": "html"
}
  • The translated response will keep all the <span class="notranslate"> content exactly as it was, while translating the rest of the text.

Quick Notes

  • Make sure your Azure Translator resource has the necessary permissions for custom terminology or HTML processing (most tiers include this by default, but double-check if you’re on a free plan).
  • If you’re using an SDK (like C# or Python), don’t forget to set the TextType property in your request object—don’t just add it to the raw JSON.
  • Test with a small batch first to confirm the untranslatable content is preserved correctly before scaling up.

内容的提问来源于stack exchange,提问作者Tom Woolway

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:44:56