Overview
This sample code provides guidance on how to use the Custom Translator API (preview) using ASP.NET MVC application. Refer to Custom Translator documentation to know more about different features of Custom Translator.
Custom Translator API (preview) documentation can be found here.
For support, please select the 'Issues' tab at the top of the page and submit your request.
Prerequisites
Follow the instructions here to create a translator resource.
Setup MVC App Code
:warning: WARNING |
Custom Translator non-interactive API is designed for automated workflows. Once the workspace is created with the API, you cannot view it in Custom Translator Portal. To be able to see the workspace, projects, documents, and models, you should create the workspace using Custom Translator portal first then use the API with the workspace Id to upload documents, create projects and train models. |
Run Visual Studio, open CustomTranslatorSampleCode.sln and expand CustomTranslatorSampleCode.
In CustomTranslatorAPIClient.cs update the following code:
- subscription_key: update this value with one of the subscription keys of your translator resource, you can fetch it from the "Keys and Endpoint" tab in the translator resource on azure portal
- resource_name: update this value with your Translator resource's name.
In Controllers folder open WorkspaceController.cs, and update following code:
- translatorResource_Location: Update this value with the location for your translator resource, can be found on overview page of the resource on the azure portal. eg: 'West US 2'
- translatorResource_SubscriptionKey: update this value with one of the subscription keys of your translator resource, you can fetch it from the "Keys and Endpoint" tab in the translator resource on azure portal
- newWorkspace.Name: update this value with desired workspace name.
To create the workspace, start the project in Visual Studio
In the home page, click on "Execute" to create a workspace. This will give you the WorkspaceId
Follow the same procedure to execute the changes after each code update.
In Controllers folder open ProjectController.cs, go to Create() method and update following code:
- workspaceId: update this value with your workspace Id. You can get this by running the "
- 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:
- workspaceId: update this value with your workspace Id.
- 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.LanguageCode: 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.LanguageCode: 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:
- workspaceId: update this value with your workspace Id.
- 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.
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.
Build the code and run it in Visual Studio to verify everything is working.