CognitiveServices.Translator.Client 1.0.0

CognitiveServices Translator Client for the V3 of the API.

Install-Package CognitiveServices.Translator.Client -Version 1.0.0
dotnet add package CognitiveServices.Translator.Client --version 1.0.0
<PackageReference Include="CognitiveServices.Translator.Client" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CognitiveServices.Translator.Client --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

CognitiveServices.Translator.Client

Microsoft Cognitive Services client. This code/package tries to cover the version 3 (V3) of the Translator Text API reference. Basically, we can have 2,000,000 character translated per month using that API. Also, it provides some feature that other API are not (like what was translated by what within the translate service).

Target

This library targets the NetStandard 2.0, so you can use it within .Net Core 2.0.

Cover the following implementations

How to install

Simply install using the Nuget package manager on your project and search for the CognitiveServices.Translator.Client package.

Or, you may simply use the command line and do Install-Package CognitiveServices.Translator.Client -Version 1.0.0.

How to use

A few choices exists, I will be presenting the most common scenario with the DI (Dependency Injection).

appsettings.json

In the settings, add the following:

"CognitiveServices": {
  "Name": "Doc_Transl_demo",
  "SubscriptionKey": "[Insert Key here]",
  "SubscriptionKeyAlternate": "Second key here"
}

Startup.cs

// During the service registration
services.AddCognitiveServices(configuration); // where configuration is IConfiguration
services.AddScoped<ITranslate, SampleClassWithInjection>(); // Where ITranslate is your own interface, not something required.

SampleClassWithInjection.cs

public class SampleClassWithInjection: ITranslate {
  private readonly ITranslateClient _translateClient;
  private readonly ILogger<SampleClassWithInjection> _logger;

  public SampleClassWithInjection(ITranslateClient translateClient, ILogger<SampleClassWithInjection> logger) {
    _translateClient = translateClient;
    _logger = logger;
  }

  public IList<ResponseBody> TranslateSomething(string text) {
    var response = _translateClient.Translate(
      new RequestContent(text),
      new RequestParameter
      {
        From = "ja", // Optional, will be auto-discovered
        To = new[] { "en" }, // You can translate to multiple language at once.
        IncludeAlignment = true, // Return what was translated by what. (see documentation)
      });

    // response = array of sentenses + array of target language
    _logger.LogDebug(response.First().Translations.First().Text);
    
    return response;
  }
}

By example: If I send A恕悓, I wil receive Mr.A.. (Better example to come)

Author(s)

  • @Nordes (me)

License

MIT

CognitiveServices.Translator.Client

Microsoft Cognitive Services client. This code/package tries to cover the version 3 (V3) of the Translator Text API reference. Basically, we can have 2,000,000 character translated per month using that API. Also, it provides some feature that other API are not (like what was translated by what within the translate service).

Target

This library targets the NetStandard 2.0, so you can use it within .Net Core 2.0.

Cover the following implementations

How to install

Simply install using the Nuget package manager on your project and search for the CognitiveServices.Translator.Client package.

Or, you may simply use the command line and do Install-Package CognitiveServices.Translator.Client -Version 1.0.0.

How to use

A few choices exists, I will be presenting the most common scenario with the DI (Dependency Injection).

appsettings.json

In the settings, add the following:

"CognitiveServices": {
  "Name": "Doc_Transl_demo",
  "SubscriptionKey": "[Insert Key here]",
  "SubscriptionKeyAlternate": "Second key here"
}

Startup.cs

// During the service registration
services.AddCognitiveServices(configuration); // where configuration is IConfiguration
services.AddScoped<ITranslate, SampleClassWithInjection>(); // Where ITranslate is your own interface, not something required.

SampleClassWithInjection.cs

public class SampleClassWithInjection: ITranslate {
  private readonly ITranslateClient _translateClient;
  private readonly ILogger<SampleClassWithInjection> _logger;

  public SampleClassWithInjection(ITranslateClient translateClient, ILogger<SampleClassWithInjection> logger) {
    _translateClient = translateClient;
    _logger = logger;
  }

  public IList<ResponseBody> TranslateSomething(string text) {
    var response = _translateClient.Translate(
      new RequestContent(text),
      new RequestParameter
      {
        From = "ja", // Optional, will be auto-discovered
        To = new[] { "en" }, // You can translate to multiple language at once.
        IncludeAlignment = true, // Return what was translated by what. (see documentation)
      });

    // response = array of sentenses + array of target language
    _logger.LogDebug(response.First().Translations.First().Text);
    
    return response;
  }
}

By example: If I send A恕悓, I wil receive Mr.A.. (Better example to come)

Author(s)

  • @Nordes (me)

License

MIT

Version History

Version Downloads Last updated
1.0.0 1,089 5/30/2018