All Products
Search
Document Center

Machine Translation:.NET SDK

Last Updated:Nov 02, 2022

Download URL

The Machine Translation . NET SDK allows developers of the Windows platform to use Alibaba Cloud Machine Translation conveniently through the .NET platform. Currently, the SDK supports . NET Framework 3.5, 4.0, and 4.5. SDK files vary with different .NET Framework versions, but the interfaces and functions are the same.

The GitHub address of the SDK is as follows: Click Here to access GitHub.

You also need to download the Alibaba Cloud . NET SDK

Procedure

To quickly start using the Machine Translation . NET 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

To use the Machine Translation. NET SDK, you must apply for an Alibaba Cloud Access Key.

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.

Step 3. Install the . NET development environment

Currently, the Machine Translation SDK supports . the .NET 3.5 and .NET 4.0/4.5 running environments. To support Machine Translation SDK development, we recommend that you install:

  • Microsoft. Net Framework 3.5/4.0/4.5 (the specific version depends on the target environment required by your program.)

  • Visual Studio 2010 and later versions

  • We recommend that you download the Alibaba Cloud . NET SDK

Step 4. Download and install the Machine Translation. NET SDK

Install the Log Service After the .NET development environment is installed, install the Machine Translation . NET SDK. Details:

1. Download

Download the .NET SDK at GitHub: here

2. Note

If you are using Visual Studio 2017 to open the project, unload the feature test project inside the project solution. It is advised to install SDK using NuGet. Do not perform compilation.Examples of NuGet installation command:

  • dotnet add package aliyun-net-sdk-ros-version 2.2.8

  • dotnet add package aliyun-net-sdk-alimt

Step 5. Start a . NET program

using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.alimt.Model.V20181012;

class TestProgram
{
    static void Main(string[] args)
    {

        IClientProfile profile = DefaultProfile.GetProfile(
            "cn-hangzhou",
            "<your-access-key-id>",
            "<your-access-key-secret>");
        DefaultAcsClient client = new DefaultAcsClient(profile);
        try
        {

            TranslateGeneralRequest request = new TranslateGeneralRequest();
            request.Method = "POST"; 
            request.FormatType = "text"; 
            request.SourceLanguage = "en"; 
            request.SourceText = "Hello";
            request.TargetLanguage = "zh"; 



            TranslateGeneralResponse response = client.GetAcsResponse(request);
            System.Console.WriteLine(response.Data);
        }
        catch (ServerException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
        catch (ClientException ex)
        {
            System.Console.WriteLine(ex.ToString());
        }
    }
}