This document describes how to call the API for Machine Translation General-purpose Edition.
Notes
1. The queries per second (QPS) limit is 50. To increase the limit, contact us in DingTalk group 23369411.
3. The maximum length is 5,000 characters. If your text exceeds this limit, you can save it as a file and use Document Translation.
4. Before you use this API, make sure that you understand the billing methods and pricing for the Machine Translation General-purpose Edition.
Debug
Request parameters
Name | Type | Required | Sample value | Description |
Action | String | Yes | TranslateGeneral | A required parameter. Set the value to TranslateGeneral. |
FormatType | String | Yes | text | The format of the text to be translated. Set the value to `html` to process the source and translated text as HTML. Set the value to `text` to process them as plain text. |
Scene | String | Yes | general | The default value for the General-purpose Edition is `general`. |
SourceLanguage | String | Yes | zh | The source language. For more information, see language codes. |
SourceText | String | Yes | Hello | The content to be translated. |
TargetLanguage | String | Yes | en | The target language. For more information, see language codes . |
Context | String | No | I ate bread at home this morning. | Contextual information. This parameter is optional. |
Returned data
Name | Type | Example value | Description |
Code | Integer | 200 | The error code. |
Data | Struct | The returned data. | |
Translated | String | Hello | The translation result. |
WordCount | String | 10 | The total number of words. |
DetectedLanguage | String | zh | The code of the source language that is detected when the source language is set to auto. |
Message | String | success | The returned message. |
RequestId | String | 86D18195-D89C-4C8C-9DC4-5FCE789CE6D5 | The ID of the request. |
Examples
Sample request
http(s)://[Endpoint]/?Action=TranslateGeneral
&FormatType=text
&Scene=general
&SourceLanguage=zh
&SourceText=Hello
&TargetLanguage=en
&<Common request parameters>For more information about common request parameters, see RPC mechanism.
Sample responses
XML format
<TranslateGeneralResponse>
<RequestId>14E447CA-B93B-4526-ACD7-42AE13CC2AF6</RequestId>
<Data>
<Translated>Hello</Translated>
</Data>
<Code>200</Code>
</TranslateGeneralResponse>JSON format
{
"TranslateGeneralResponse": {
"RequestId": "14E447CA-B93B-4526-ACD7-42AE13CC2AF6",
"Data": {
"Translated": "Hello"
},
"Code": 200
}
}Error codes
HTTP status code | Error code | Error message | Description |
101 | 10001 | The request has timed out. | The request timed out. |
102 | 10002 | A system error occurred. | A system error occurred. |
103 | 10003 | An error occurred while decoding the URL. Verify that the specified URL is encoded. | Failed to decode the source text. Check whether the source text is URL-encoded. |
104 | 10004 | Some required parameters are missing. | A required parameter is missing. |
105 | 10005 | The specified language pair is not supported. | The term is not supported. |
106 | 10006 | An error occurred while detecting the language. | Failed to detect the language. |
107 | 10007 | An error occurred while translating. | The translation failed. |
108 | 10008 | The specified string is too long. | The text is too long. |
199 | 19999 | An unknown error occurred. | An unknown error occurred. |
109 | 10009 | The RAM user does not have the required permissions. | The RAM user does not have the required permissions. |
110 | 10010 | The service is not activated for the account. | The service is not activated for the account. |
111 | 10011 | The service failed for the RAM user. | The service failed for the RAM user. |
112 | 10012 | The call to the translation service failed. | The call to the translation service failed. |
113 | 10013 | The service is not activated for the account or the account has an overdue payment. | The service is not activated for the account or the account has an overdue payment. |
For more information about error codes, see Error Center.