GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Nordes/CognitiveServices.Translator.Client: Microsoft Cognitive Services (API V3.0) wrapper (html/text Translator, etc.)

BranchesTags
Open more actions menu

Latest commit

 

History

47 Commits
47 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
CognitiveServices.Translator.Client.IntegrationTests
CognitiveServices.Translator.Client.IntegrationTests
 
 
CognitiveServices.Translator.Client.UnitTests
CognitiveServices.Translator.Client.UnitTests
 
 
CognitiveServices.Translator.Client.WebSample
CognitiveServices.Translator.Client.WebSample
 
 
CognitiveServices.Translator.Client
CognitiveServices.Translator.Client
 
 
.gitignore
.gitignore
 
 
CognitiveServices.Translator.Client.sln
CognitiveServices.Translator.Client.sln
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
createArtifacts.ps1
createArtifacts.ps1
 
 
nupack.ps1
nupack.ps1
 
 

Repository files navigation

Build status NuGet Nuget

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/Nuget package targets the NetStandard 2.0, so you can use it within .Net Core 2.0.

Cover the following implementations

  • Language API
    • 100% implemented.
    • Does not require a Cognitive Services API Key
    • Require some tests.
    • Cache is not implemented perfectly (not yet using the ETag nor invalidating before a next restart).
  • Translate API
    • 100% implemented.
    • Demo available at cstranslatordemo.azurewebsites.net
    • Todo: Automated integration tests would be a nice to have in order to detect API changes.
  • Transliterate API
    • Not yet available
  • Detect API
    • Not yet available
  • Break sentence API
    • Not yet available
  • Dictionary Lookup API
    • Not yet available
  • Dictionary Example API
    • Not yet available

How to install (Nuget)

Choice 1 Nuget package manager

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

Choice 2 use the command line

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",
  "SubscriptionRegion": "[Region here, optional]"
}

Startup.cs

// During the service registration
services.AddCognitiveServicesTranslator(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 sentences + 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

  • @Nordes (me)

Contrib

  • @dmitriybobrovskiy
  • @Phrohdoh

License

MIT

About

Microsoft Cognitive Services (API V3.0) wrapper (html/text Translator, etc.)

Topics

cognitive-servicescognitiveservicesmicrosoft-translator-apimicrosoft-translator-servicenugetnuget-packagetranslator

Resources

Readme
MIT license
Activity

Stars

7 stars

Watchers

3 watching

Forks

6 forks
Report repository

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.