Translates text or HTML content from a source language to a target language using the TranslateGeneral operation.
Limitations
QPS limit: 50. Contact us via DingTalk group 23369411 to request a higher limit.
Maximum input length: 5,000 characters. For longer content, use Document Translation.
Review the pricing for Machine Translation Universal Edition before calling this API.
2, please ensure that the use of the interface, has fully understood the universal version translation products charging methods and prices
Debugging
Call TranslateGeneral directly in OpenAPI Explorer, which generates sample code for different SDKs automatically.
Request parameters
| Parameter | Type | Required | Example | Description |
|---|---|---|---|---|
| Action | String | Yes | TranslateGeneral | The operation to perform. Set to TranslateGeneral. |
| FormatType | String | Yes | text | The format of the source text. Valid values: text (plain text, no format processing applied), html (HTML content, tags are preserved in output). |
| Scene | String | Yes | general | The translation domain. Set to general for the Universal Edition. |
| SourceLanguage | String | Yes | zh | The source language code. Set to auto to enable automatic language detection. For supported language codes, see Language codes. |
| SourceText | String | Yes | Hello | The source text to translate. |
| TargetLanguage | String | Yes | en | The target language code. For supported language codes, see Language codes. |
Response elements
| Parameter | Type | Example | Description |
|---|---|---|---|
| Code | Integer | 200 | The HTTP status code. |
| Data | Struct | — | The translation result. |
| └ Translated | String | Hello | The translated text. |
| └ WordCount | String | 10 | The word count of the source text. |
| └ DetectedLanguage | String | zh | The detected language code of the source text. Returned only when SourceLanguage is set to auto. |
| Message | String | success | The response message. |
| RequestId | String | 86D18195-D89C-4C8C-9DC4-5FCE789CE6D5 | The request ID. |
Examples
Sample request
http(s)://[Endpoint]/?Action=TranslateGeneral
&FormatType=text
&Scene=general
&SourceLanguage=en
&SourceText=Hello
&TargetLanguage=zh
&<Common request parameters>Sample success response
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. | The source text could not be decoded. Verify that the text is URL encoded. |
| 104 | 10004 | Some required parameters are missing. | One or more required parameters were not provided. |
| 105 | 10005 | The specified language pair is not supported. | The combination of source and target language is not supported. |
| 106 | 10006 | An error occurred while detecting the language. | Language detection failed. |
| 107 | 10007 | An error occurred while translating. | The translation failed. |
| 108 | 10008 | The specified string is too long. | The source text exceeds the maximum length. |
| 109 | 10009 | The RAM user has no permissions. | The RAM user does not have permission to call this operation. |
| 110 | 10010 | The account does not activate the service. | Machine Translation is not activated for this account. |
| 111 | 10011 | Sub-account service failure | The RAM user encountered a service error. |
| 112 | 10012 | Translation service call failed | The translation service call failed. |
| 113 | 10013 | The account service is not activated or the payment is overdue. | Machine Translation is not activated or the account has an overdue payment. |
| 199 | 19999 | An unknown error occurred. | An unknown error occurred. |
For the full list of error codes, see Service error codes.