All Products
Search
Document Center

GO SDK

Last Updated: Jun 13, 2019

Download URL

The download URL of the Machine Translation Go SDK is as follows:https://help.aliyun.com/document_detail/63640.html?spm=a2c4g.11186623.6.604.2dc7667atjC0sa

Procedure

To quickly start using the Machine Translation Go SDK, take the following steps:

Step 1. Create an Alibaba Cloud account

For more information about how to create an Alibaba Cloud account, see Sign up with Alibaba Cloud.

We recommend that you complete real-name authentication as soon as possible to better use Alibaba Cloud services. Otherwise, some services may be unavailable.

Step 2. Obtain an Alibaba Cloud Access Key

You must apply for an Alibaba Cloud Access Key for using the Machine Translation Go SDK.

Log on to Alibaba Cloud’s Access Key Management page. Select an Access Key (consisting of an Access Key ID and Access Key Secret) for the SDK. If you do not have an Access Key, create one and make sure the Access Key is enabled.

The Access Key will be used in the following steps and must be kept confidential.

Step 3. Start a GO program

Now, you can start using the Python SDK. Use any text editor or the Python IDE to run the following sample code, and you can interact with the Machine Translation server and obtain the relevant output.

  1. package main
  2. import (
  3. "github.com/aliyun/alibaba-cloud-sdk-go/services/alimt"
  4. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
  5. "fmt"
  6. )
  7. func main() {
  8. // Create an instance
  9. alimtClient, err := alimt.NewClientWithAccessKey(
  10. "cn-hangzhou", // Region
  11. "<your-access-key-id>", // Access Key ID
  12. "<your-access-key-secret>") // Access Key Secret
  13. if err != nil {
  14. // Exception handling
  15. panic(err)
  16. }
  17. // Create API requests and set parameters
  18. request := alimt.CreateTranslateECommerceRequest()
  19. request.Method = "POST"; //Set request method,POST
  20. request.FormatType = "text"; //Format of translated text
  21. request.SourceLanguage = "en"; //Source language
  22. request.SourceText = "book"; //Source Text
  23. request.TargetLanguage = "zh"; //Target language
  24. request.Scene = "title"; //Target language
  25. // Initiate a request and handle the exception
  26. response, err := alimtClient.TranslateECommerce(request)
  27. if err != nil {
  28. // Exception handling
  29. panic(err)
  30. }
  31. fmt.Println(response)
  32. }