文本翻译 API 如何计算字符数How the Translator Text API counts characters

文本翻译 API 将输入文本的每个 Unicode 码位计为一个字符。The Translator Text API counts every Unicode code point of input text as a character. 文本到某种语言的每个翻译都计为单独的翻译,即使在单个 API 调用中发出翻译为多种语言的请求时也是如此。Each translation of a text to a language counts as a separate translation, even if the request was made in a single API call translating to multiple languages. 响应的长度无关紧要。The length of the response does not matter.

计数对象为:What counts is:

  • 在请求正文中传递到文本翻译 API 的文本Text passed to the Translator Text API in the body of the request
    • Text(如果使用 Translate、Transliterate 和 Dictionary Lookup 方法)Text when using the Translate, Transliterate, and Dictionary Lookup methods
    • TextTranslation(如果使用 Dictionary Examples 方法)Text and Translation when using the Dictionary Examples method
  • 所有标记:请求正文文本字段内的 HTML、XML 标记等。All markup: HTML, XML tags, etc. within the text field of the request body. 用于生成请求的 JSON 表示法(例如,“Text:”)不计入。JSON notation used to build the request (for instance "Text:") is not counted.
  • 单个字母An individual letter
  • 标点Punctuation
  • 空格、制表符、标记和任何类型的空格字符A space, tab, markup, and any kind of white space character
  • Unicode 中定义的每个码位Every code point defined in Unicode
  • 重复的翻译(即使之前已翻译相同的文本)A repeated translation, even if you have translated the same text previously

对于基于表意文字(例如中文汉字和日文汉字)的脚本,文本翻译 API 仍会对 Unicode 码位的数量计数,每个表意文字计为一个字符。For scripts based on ideograms such as Chinese and Japanese Kanji, the Translator Text API will still count the number of Unicode code points, one character per ideogram. 异常:Unicode 代理项计为两个字符。Exception: Unicode surrogates count as two characters.

请求、单词、字节或句子的数量在字符计数中不相关。The number of requests, words, bytes, or sentences is irrelevant in the character count.

对 Detect 和 BreakSentence 方法的调用不计入字符消耗。Calls to the Detect and BreakSentence methods are not counted in the character consumption. 但是,我们希望 Detect 和 BreakSentence 方法的调用次数与其他计数函数的使用次数成合理的比例。However, we do expect that the calls to the Detect and BreakSentence methods are in a reasonable proportion to the use of other functions that are counted. 如果发出的 Detect 或 BreakSentence 调用的数量是其他计数方法数量的 100 倍,Microsoft 保留限制使用 Detect 和 BreakSentence 方法的权利。If the number of Detect or BreakSentence calls you make exceeds the number of other counted methods by 100 times, Microsoft reserves the right to restrict your use of the Detect and BreakSentence methods.

有关字符计数的详细信息,请参阅 Microsoft Translator FAQMore information about character counts is in the Microsoft Translator FAQ.