GithubHelp home page GithubHelp logo

keenmate / cognitiveservices.translator.client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nordes/cognitiveservices.translator.client

0.0 3.0 0.0 161 KB

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

License: MIT License

C# 62.67% JavaScript 15.50% Vue 14.47% CSS 3.40% HTML 0.61% Dockerfile 1.27% PowerShell 2.08%

cognitiveservices.translator.client's Introduction

Build status 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

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"
}

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 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's People

Contributors

nordes avatar phrohdoh avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.