meta info
  • Title: Use Google Translation For Localization
  • Keywords: localization, asp.net-core, translate, online, google, service
  • Description: Learn how to use mymemory translation service for localization of Asp.Net Core web apps with XLocalizer.Translate.
  • Author: Ziya Mollamahmut
  • Date: 12-Nov-2020
  • Image: https://github.com/LazZiya/Docs/raw/master/XLocalizer/v1.0/images/xlocalizer-logo.png
  • Image-alt: XLocalizer Logo
  • Version: v1.0

Use Google Translate For Localization

By Ziya Mollamahmut

This nuget containes two services, you can use any of them depending on your requirements:

See GitHub repo

Install

PM > Install-Package XLocalizer.Translate.GoogleTranslate

GoogleTranslateService

This service is directly connected to Google Translate Api's, and it offers free usage, but it requires a subscription!

{
  "XLocalizer.Translate": {
    "Google": {
        "Key": "..."
    }
  }
}

Right click on the project name and select Manage User Secrets

  • Register in startup
services.AddHttpClient<ITranslator, GoogleTranslateService>();
  • Use with XLocalizer
services.AddRazorPages()
        .AddXLocalizer<LocSource, GoogleTranslateService>(ops =>
        {
            // ...
            ops.AutoTranslate = true;
        });

GoogleTranslateServiceRapidApi

This service is connected to RapidApi, and it requires a RapidApi key and a subscription to any paid or free plan.

{
  "XLocalizer.Translate": {
    "RapidApiKey": "...",
  }
}

Right click on the project name and select Manage User Secrets

  • Register in startup
services.AddHttpClient<ITranslator, GoogleTranslateServiceRapidApi>();
  • Use with XLocalizer
services.AddRazorPages()
        .AddXLocalizer<LocSource, GoogleTranslateServiceRapidApi>(ops =>
        {
            // ...
            ops.AutoTranslate = true;
        });