All Products
Search
Document Center

Development of Guidelines

Last Updated: Jul 01, 2019

API description

APIs of the general-purpose version

Trial

  1. `TranslateGeneralRequest generalRequest = new TranslateGeneralRequest();`
  2. generalRequest.setMethod`(MethodType.POST); // Sets the method to POST.`
  3. generalRequest.setFormatType`(`"text"`); `//Format of the translated text``
  4. generalRequest.setSourceLanguage`("en"); //Source language`
  5. generalRequest.setSourceText`(URLEncoder.encode("hello","UTF-8")); //Source text`
  6. generalRequest.setTargetLanguage`("zh"); //Target language`

APIs of the e-commerce edition

Trial

  1. `TranslateECommerceRequest eCommerceRequest = new TranslateECommerceRequest();`
  2. eCommerceRequest.setScene`("title");`
  3. eCommerceRequest.setMethod`(MethodType.POST); // Sets the method to POST.`
  4. eCommerceRequest.setFormatType`("text"); //Format of the translated text`
  5. eCommerceRequest.setSourceLanguage`("en"); //Source language`
  6. eCommerceRequest.setSourceText(URLEncoder.encode`("hello","UTF-8")); //Source text`
  7. eCommerceRequest.setTargetLanguage`("zh"); //Target language`

Description

Parameter Value
method Format of the translated text, html (web page format. After this parameter is set, the text to be translated and the text after translation are processed in the HTML format. text (text format. After this parameter is set, the input text to be translated and the translation results are processed in the plain text format, rather than the text format.
sourceText Note the following points when translating text strings: 1. Encode the text to be translated in the UTF-8 format; 2. Perform URLEncoder on the text before sending an HTTP request; 3. Ensure that the length does not exceed 5000 characters.
sourceLanguage Source language of translation. For specific values, see the following language list.
targetLanguage Target language of translation. For specific values, see the following language list.
scene Scenario. This field is only required by the e-commerce edition. The optional values are title (commodity title), description (commodity description), and communication (commodity-related communication).
region Region. Currently, this field is only set to cn-hangzhou.

Matters needing attention

1、Ensure that the length does not exceed 5000 characters.

2、User Call Interface QPS Limit 50

If more characters are needed, a larger QPS. Please contact us

Region Zone

Region regionId product endoption
Hangzhou cn-hangzhou alimt mt.cn-hangzhou.aliyuncs.com

Response

  1. {
  2. "code": 200,
  3. "data": {
  4. "translated": "book"
  5. }
  6. }

If the translation fails, the following response is returned:

  1. {
  2. "code": 10005,
  3. "message": "translate from source to target not support"
  4. }

List of languages supported by translation:

Universal edition

Version Language Description
Universal standard edition en English
Universal standard edition zh Simplified Chinese
Universal standard edition auto Automatic identification of the source language

E-commerce edition

Version Language Description
E-commerce edition en English
E-commerce edition zh Simplified Chinese
E-commerce edition ru Russian
E-commerce edition pt Portuguese
E-commerce edition es Spanish
E-commerce edition fr French
E-commerce edition tr Turkish
E-commerce edition ar Arabic
E-commerce edition th Thai
E-commerce edition vi Vietnamese
E-commerce edition id Indonesian
E-commerce edition ja Japanese
E-commerce edition pl Polish
E-commerce edition it Italian
E-commerce edition ko Korean
E-commerce edition auto Automatic identification of the source language

Error codes

Error codes Description Solution
10001 The request has timed out. Send the request again.
10002 The error message returned when a system error has occurred. Send the request again.
10003 The error message returned when URL decoding fails. Make sure that the string is encoded by using UTF-8 and URL encoding is correct.
10004 Parameters are missing. Check input parameters.
10005 The error message returned when the language is not supported. Make sure that both the source and target languages are supported.
10006 The error message returned when the system fails to recognize the string. Make sure that the string you have passed in is correct.
10007 The error message returned when the translation fails. Check whether the translated string is correct.
10008 The character length is too long. Check the character length of the source text. The source text can be called multiple times. The length is limited to 5000 characters.
10009 The RAM user is not authorized. Use the primary account to authorize the RAM user.
10010 The account does not activate the service. Activate Machine Translation first.
10011 The RAM user encounters a service failure. Contact Customer Support.
10012 The translation service cannot be called. Contact Customer Support.
10013 The account does not activate the service or has overdue payment. Activate the service or clear the overdue payment.
19999 An unknown error has occurred. Contact Customer Support.

Use the primary account to authorize the RAM user.

Authorization configuration

  1. MyAlimtFullAccess
  2. {
  3. "Statement": [
  4. {
  5. "Effect": "Allow",
  6. "Action": "alimt:*",
  7. "Resource": "*"
  8. }
  9. ],
  10. "Version": "1"
  11. }

Download and install the SDK

Download the latest version of the SDK from the Maven server:

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>4.3.2</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.aliyun</groupId>
  8. <artifactId>aliyun-java-sdk-alimt</artifactId>
  9. <version>1.0.3</version>
  10. </dependency>

Java sample code

  1. public static void main(String[] args) {
  2. try {
  3. DefaultProfile profile = DefaultProfile.getProfile(
  4. "cn-hangzhou", // Region ID
  5. accessKeyId, // AccessKey ID
  6. accessKeySecret); // Access Key Secret
  7. IAcsClient client = new DefaultAcsClient(profile);
  8. // Create API requests and set parameters
  9. TranslateECommerceRequest request = new TranslateECommerceRequest();
  10. eCommerceRequest.setScene("title"); //set scene
  11. request.setMethod(MethodType.POST); // Set request method,POST
  12. request.setFormatType("text"); //Format of translated text
  13. request.setSourceLanguage("en"); //source Language
  14. request.setSourceText(URLEncoder.encode("book","UTF-8")); //source text
  15. request.setTargetLanguage("zh"); // target language
  16. TranslateECommerceResponse response = client.getAcsResponse(request);
  17. System.out.println(JSONObject.toJSON(response));
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. }
  21. }