翻译器 3.0:TransliterateTranslator 3.0: Transliterate

将一种语言的文本从一个脚本转换为另一个脚本。Converts text in one language from one script to another script.

请求 URLRequest URL

POST 请求发送到:Send a POST request to:

https://api.translator.azure.cn/transliterate?api-version=3.0

请求参数Request parameters

查询字符串上传递的请求参数如下:Request parameters passed on the query string are:

查询参数Query parameter 说明Description
api-versionapi-version 必需参数。*Required parameter*.
客户端所请求的 API 的版本。Version of the API requested by the client. 值必须是 `3.0`。Value must be `3.0`.
语言language 必需参数。*Required parameter*.
指定要从一个脚本转换为另一个脚本的文本的语言。Specifies the language of the text to convert from one script to another. 通过查询服务的[支持的语言](./v3-0-languages.md)获得的 `transliteration` 范围中列出了可能的语言。Possible languages are listed in the `transliteration` scope obtained by querying the service for its [supported languages](./v3-0-languages.md).
fromScriptfromScript 必需参数。*Required parameter*.
指定输入文本所使用的脚本。Specifies the script used by the input text. 使用 `transliteration` 范围查找[支持的语言](./v3-0-languages.md),以找到可用于选定语言的输入脚本。Look up [supported languages](./v3-0-languages.md) using the `transliteration` scope, to find input scripts available for the selected language.
toScripttoScript 必需参数。*Required parameter*.
指定输出脚本。Specifies the output script. 使用 `transliteration` 范围查找[支持的语言](./v3-0-languages.md),以找到可用于选定输入语言和输入脚本组合的输出脚本。Look up [supported languages](./v3-0-languages.md) using the `transliteration` scope, to find output scripts available for the selected combination of input language and input script.

请求标头包括:Request headers include:

头文件Headers 说明Description
身份验证标头Authentication header(s) 必需的请求标头。Required request header.
请参阅用于身份验证的可用选项See available options for authentication.
Content-TypeContent-Type 必需的请求标头。*Required request header*.
指定有效负载的内容类型。Specifies the content type of the payload. 可能的值为:`application/json`Possible values are: `application/json`.
Content-LengthContent-Length 必需的请求标头。*Required request header*.
请求正文的长度。The length of the request body.
X-ClientTraceIdX-ClientTraceId 可选。*Optional*.
客户端生成的 GUID,用于唯一标识请求。A client-generated GUID to uniquely identify the request. 请注意,如果在查询字符串中使用名为 `ClientTraceId` 的查询参数包括了跟踪 ID,则可以省略此标头。Note that you can omit this header if you include the trace ID in the query string using a query parameter named `ClientTraceId`.

请求正文Request body

请求的正文是一个 JSON 数组。The body of the request is a JSON array. 每个数组元素都是一个 JSON 对象,具有一个名为 Text 的字符串属性,该属性表示要转换的字符串。Each array element is a JSON object with a string property named Text, which represents the string to convert.

[
    {"Text":"こんにちは"},
    {"Text":"さようなら"}
]

以下限制适用:The following limitations apply:

  • 该数组最多可具有 10 个元素。The array can have at most 10 elements.
  • 数组元素的文本值不能超过 1,000 个字符(包括空格)。The text value of an array element cannot exceed 1,000 characters including spaces.
  • 包括空格在内,请求中包含的整个文本不能超过 5,000 个字符。The entire text included in the request cannot exceed 5,000 characters including spaces.

响应正文Response body

成功的响应是一个 JSON 数组,其中的每个结果对应于输入数组中的一个元素。A successful response is a JSON array with one result for each element in the input array. 结果对象包括以下属性:A result object includes the following properties:

  • text:一个字符串,它是将输入字符串转换为输出脚本的结果。text: A string which is the result of converting the input string to the output script.

  • script:一个字符串,指定输出中使用的脚本。script: A string specifying the script used in the output.

示例 JSON 响应如下:An example JSON response is:

[
    {"text":"konnnichiha","script":"Latn"},
    {"text":"sayounara","script":"Latn"}
]

响应标头Response headers

头文件Headers 说明Description
X-RequestIdX-RequestId 服务生成的用于标识请求的值。Value generated by the service to identify the request. 它用于故障排除目的。It is used for troubleshooting purposes.

响应状态代码Response status codes

下面是请求可能返回的 HTTP 状态代码。The following are the possible HTTP status codes that a request returns.

状态代码Status Code 说明Description
200200 成功。Success.
400400 查询参数之一缺失或无效。One of the query parameters is missing or not valid. 请更正请求参数,然后重试。Correct request parameters before retrying.
401401 无法对请求进行身份验证。The request could not be authenticated. 请确保凭据已指定且有效。Check that credentials are specified and valid.
403403 请求未经授权。The request is not authorized. 请检查详细错误消息。Check the details error message. 这通常表示试用订阅提供的所有可用翻译已用完。This often indicates that all free translations provided with a trial subscription have been used up.
429429 由于客户端已超出请求限制,服务器拒绝了请求。The server rejected the request because the client has exceeded request limits.
500500 发生了意外错误。An unexpected error occurred. 如果错误持续存在,请报告相关信息:发生故障的日期和时间、响应标头 `X-RequestId` 中的请求标识符、请求标头 `X-ClientTraceId` 中的客户端标识符。If the error persists, report it with: date and time of the failure, request identifier from response header `X-RequestId`, and client identifier from request header `X-ClientTraceId`.
503503 服务器暂不可用。Server temporarily unavailable. 重试请求。Retry the request. 如果错误持续存在,请报告相关信息:发生故障的日期和时间、响应标头 `X-RequestId` 中的请求标识符、请求标头 `X-ClientTraceId` 中的客户端标识符。If the error persists, report it with: date and time of the failure, request identifier from response header `X-RequestId`, and client identifier from request header `X-ClientTraceId`.

如果发生错误,请求也会返回 JSON 错误响应。If an error occurs, the request also returns a JSON error response. 错误代码是一个 6 位数字,包括 3 位数的 HTTP 状态代码,后接用于进一步将错误分类的 3 位数。The error code is a 6-digit number combining the 3-digit HTTP status code followed by a 3-digit number to further categorize the error. 常见错误代码可在 v3 翻译器参考页上找到。Common error codes can be found on the v3 Translator reference page.

示例Examples

以下示例显示如何将两个日语字符串转换为用罗马字母拼写的日语。The following example shows how to convert two Japanese strings into Romanized Japanese.

此示例中请求的 JSON 有效负载:The JSON payload for the request in this example:

[{"text":"こんにちは","script":"jpan"},{"text":"さようなら","script":"jpan"}]

若要在不支持 Unicode 字符的命令行窗口中使用 cURL,请获取以下 JSON 有效负载,并将它保存到 request.txt 文件中。If you are using cURL in a command-line window that does not support Unicode characters, take the following JSON payload and save it into a file named request.txt. 请务必使用 UTF-8 编码保存文件。Be sure to save the file with UTF-8 encoding.

curl -X POST "https://api.translator.azure.cn/transliterate?api-version=3.0&language=ja&fromScript=Jpan&toScript=Latn" -H "X-ClientTraceId: 875030C7-5380-40B8-8A03-63DACCF69C11" -H "Ocp-Apim-Subscription-Key: <client-secret>" -H "Ocp-Apim-Subscription-Region: your-region" -H "Content-Type: application/json" -d @request.txt