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 [email protected] for questions and support.
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.
Enter application name and click on Create.
Generate a new password and keep it safe. This is the Application Secret, and will be used in the application for authentication.
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.
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.
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.
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.
After you’ve provided consent, a popup window for terms will be shown. Read and accept the terms to continue.
Run Visual Studio, open CustomTranslatorSampleCode.sln and expand CustomTranslatorSampleCode.
In Controllers folder open HomeController.cs, and update following code:
- clientID: update this value with the App Id/Client ID listed in Application Registration Portal.
- clientsecret: update this value with your App’s secret/ password.
- redirectUri: update it as per your MVC app’s URL.
- session Session["ws_id"]: update this variable based on your workspace ID.
In Controllers folder open ModelController.cs, go to Create() method and update following code:
- model.name: update this value desired model name.
- model.projectId: update this value with your project id.
- model.documentIds.Add(): add document id in this list. You can add multiple documents.
In Controllers folder open ProjectController.cs, go to Index() method and update following code:
- newproject.name: update this value desired project name.
- newproject.languagePairId: update this value with appropriate language pair id.
- newproject.categoryid: update this value with appropriate category id.
- newproject.categoryDescriptor: update this value desired project category descriptor.
- newproject.label: update this value desired project label.
- newproject.description: update this value desired project description.
In Controllers folder open UploadController.cs, go to ParallelFile() method and update following code:
- sourcelanguagefilepath: update this value of the local path for source language file.
- targetlanguagefilepath: update this value of the local path for source target file.
- documentdetails.DocumentName: update this value with desired document name.
- documentdetails.DocumentType: update this value desired document type. Values can be of training/ tuning/ testing.
- sourcelanguagefile.Language: update this value with source language code.
- sourcelanguagefile.OverwriteIfExists: if you want to overwrite with this file, if the same file name exists use true, else use false.
- targetlanguagefile.Language: update this value with target language code.
- targetlanguagefile.OverwriteIfExists: if you want to overwrite with this file, if the same file name exists use true, else use false.
In Controllers folder open UploadController.cs, go to ComboFile() method and update following code:
- filepath: update this value of the local path for combo file.
- documentdetails.DocumentName: update this value with desired document name.
- documentdetails.DocumentType: update this value desired document type. Values can be of training/ tuning/ testing.
Build the code and run it in Visual Studio to verify everything is working.