meta info
  • Title: Use IBM Watson Language Translator For Localization
  • Keywords: localization, asp.net-core, translate, online, ibm, watson, language, translator, service
  • Description: Learn how to use ibm watson language translator service for localization of Asp.Net Core web apps with XLocalizer.Translate.
  • Author: Ziya Mollamahmut
  • Date: 08-Aug-2020
  • Image: https://github.com/LazZiya/Docs/raw/master/XLocalizer/v1.0/images/xlocalizer-logo.png
  • Image-alt: XLocalizer Logo
  • Version: v1.0

Use IBM Watson Language Translator For Localization

By Ziya Mollamahmut

This nuget is based on the free plan of IBM Watson Language Translator.

See GitHub repo

Install

PM > Install-Package XLocalizer.Translate.IBMWatsonTranslate

Notice: To install the latest preview add -Pre to the command line

Add API keys to user secrets

Right click on the project name and select Manage User Secrets, then add the API key as below:

{
  "XLocalizer.Translate": {
    "IBMWatsonTranslateApiKey": "xxx-imb-watson-cloud-api-key-xxx",
    "IBMWatsonTranslateServiceUrl": "xxx-ibm-service-instance-xxx",
    "IBMWatsonTranslateServiceVersionDate": "xxx-ibm-service-version-date-xxx"
  }
}

Register in startup

using XLocalizer.Translate
using XLocalizer.Translate.IBMWatsonTranslate

services.AddSingleton<ITranslator, IBMWatsonTranslateService>();

Use with XLocalizer

// Configure XLocalizer to use the translation service 
// and enable online translation
services.AddRazorPages()
        .AddXLocalizer<LocSource, IBMWatsonTranslateService>(ops =>
        {
            // ...
            ops.AutoTranslate = true;
        });