Skip to content

undeadinu/CustomTranslatorApiSamples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 

Repository files navigation

Overview

This sample code provides guidance on how to use the Custom Translator API using ASP.NET MVC application. Refer to Custom Translator documentation to know more about different features of Custom Translator.

Custom Translator API documentation can be found here.

Please contact custommt@microsoft.com for questions and support.

Prerequisites

Create and Register your Azure AD Client App

This sample code uses OAuth and OpenID for authentication. Please sign in to https://apps.dev.microsoft.com with the same user credentials you use to login to Custom Translator. The landing page shows the list of client apps that are created/ available to use with your account.

Create an app using Add an app button at top right-hand corner of the landing page.

My applications

Enter application name and click on Create.

Client app registration

Generate a new password and keep it safe. This is the Application Secret, and will be used in the application for authentication.

Generate secret

When an application is created, the default delegated permission for it are User.Read. Add two additional delegated permissions

  • offline_access
  • openid.

Go to Microsoft Graph Permissions, the Delegated Permissions in the page to add these permissions.

Client app settings

For the MVC web application, a new “Web” platform needs to be added from “Platforms” section of the page.

Enter the Redirect URLs for the web platform. This URL is where your MVC web app should redirect after authentication. You can change Redirect URLs based on your application configuration.

Client app platform

Now save the changes you made and the portal will take you to the landing page, where all your registered applications are listed. The App Id/ Client ID listed here will be used to authenticate in the MVC web app.

Client app ID

Provide Consent and Accept Terms

If you haven't already logged in to Custom Translator Portal with your user account (the same user account you used to create/register the AAD app), you will need to login to accept the terms and conditions.

After you sign in to Custom Translator portal with your user account, you will receive a popup window requesting your consent.

Consent

After you’ve provided consent, a popup window for terms will be shown. Read and accept the terms to continue.

Accept terms

Setup MVC App Code

Run Visual Studio, open CustomTranslatorSampleCode.sln and expand CustomTranslatorSampleCode.

In Controllers folder open HomeController.cs, and update following code:

  1. clientID: update this value with the App Id/Client ID listed in Application Registration Portal.
  2. clientsecret: update this value with your App’s secret/ password.
  3. redirectUri: update it as per your MVC app’s URL.

Variables

  1. session Session["ws_id"]: update this variable based on your workspace ID.

Workspace

In Controllers folder open ModelController.cs, go to Create() method and update following code:

  1. model.name: update this value desired model name.
  2. model.projectId: update this value with your project id.
  3. model.documentIds.Add(): add document id in this list. You can add multiple documents.

Workspace

In Controllers folder open ProjectController.cs, go to Index() method and update following code:

  1. newproject.name: update this value desired project name.
  2. newproject.languagePairId: update this value with appropriate language pair id.
  3. newproject.categoryid: update this value with appropriate category id.
  4. newproject.categoryDescriptor: update this value desired project category descriptor.
  5. newproject.label: update this value desired project label.
  6. newproject.description: update this value desired project description.

Workspace

In Controllers folder open UploadController.cs, go to ParallelFile() method and update following code:

  1. sourcelanguagefilepath: update this value of the local path for source language file.
  2. targetlanguagefilepath: update this value of the local path for source target file.
  3. documentdetails.DocumentName: update this value with desired document name.
  4. documentdetails.DocumentType: update this value desired document type. Values can be of training/ tuning/ testing.
  5. sourcelanguagefile.Language: update this value with source language code.
  6. sourcelanguagefile.OverwriteIfExists: if you want to overwrite with this file, if the same file name exists use true, else use false.
  7. targetlanguagefile.Language: update this value with target language code.
  8. targetlanguagefile.OverwriteIfExists: if you want to overwrite with this file, if the same file name exists use true, else use false.

Workspace

In Controllers folder open UploadController.cs, go to ComboFile() method and update following code:

  1. filepath: update this value of the local path for combo file.
  2. documentdetails.DocumentName: update this value with desired document name.
  3. documentdetails.DocumentType: update this value desired document type. Values can be of training/ tuning/ testing.

Workspace

Build the code and run it in Visual Studio to verify everything is working.

About

Custom Translator API Samples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 73.7%
  • HTML 13.5%
  • JavaScript 12.1%
  • Other 0.7%