npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@akgargo/ms-translator-api-client

v0.0.4

Published

Node JS Client Library for using Microsoft Azure Translator API

Downloads

12

Readme

Microsoft Translator API Client

non-official package that enables a Microsoft Azure Translator API Client for NodeJS

This package was created as response of a lack of official packages for consuming MS Translator API in NodeJS applications.It provides an easy way to consume their enpointsand its fully extensible by adding layers of abstraction for business logic.

This package is currently a beta version and only supports "languages", "detect", "translate" and "transliterate" endpoints of the Azure Text Translation REST API

Installing / Getting Started

This package is only available for NodeJS and should be installed using NPM by running the commands below:

Open a command line and make sure you are in your project's root directory before installing it

cd development/my-awesome-project/

Now, let's install this package

npm i @akgargo/ms-translator-api-client

Quick Start

The usage of this API client is very intuitive if you have already read the official Microsoft documentation. I higly recommend you to uderstand how the API works first, as this is only an abstracion layer that help you to reduce boilerplate code directly in your application for using MS Azure translation capabilities.

Creating a client

import { MicrosoftTextTranslator } from '@akgargo/ms-translator-api-client';

const translator = new MicrosoftTextTranslator({ subscriptionKey: <YOUR_AZURE_TRANSLATOR_KEY> })

Translating some text

translator.translate({
  text: ["Hello world", "This are two different texts to be translated in a single call"],
  to: "es"
})
.then(translation => {
  console.log(JSON.stringify({ translation }, null, 2))
});

The code above should print in the console

{
  "translation": [
    {
      "detectedLanguage": {
        "language": "en",
        "score": 1
      },
      "translations": [
        {
          "text": "Hola mundo",
          "to": "es"
        }
      ]
    },
    {
      "detectedLanguage": {
        "language": "en",
        "score": 1
      },
      "translations": [
        {
          "text": "Se trata de dos textos diferentes a traducir en una sola convocatoria",
          "to": "es"
        }
      ]
    }
  ]
}

Usage

Languages endpoint

Usage

translator.languages({}).then(languages => {
  console.log(JSON.stringify({ languages }, null, 2))
});

Result

{
  "detection": [
    {
      "translation": {
        "af": {
          "name": "Afrikaans",
          "nativeName": "Afrikaans",
          "dir": "ltr"
        },
        ....
      },
      "transliteration": {
        "ar": {
          "name": "Arabic",
          "nativeName": "العربية",
          "scripts": [
            {
              "code": "Arab",
              "name": "Arabic",
              "nativeName": "العربية",
              "dir": "rtl",
              "toScripts": [
                {
                  "code": "Latn",
                  "name": "Latin",
                  "nativeName": "اللاتينية",
                  "dir": "ltr"
                }
              ]
            },
            {
              "code": "Latn",
              "name": "Latin",
              "nativeName": "اللاتينية",
              "dir": "ltr",
              "toScripts": [
                {
                  "code": "Arab",
                  "name": "Arabic",
                  "nativeName": "العربية",
                  "dir": "rtl"
                }
              ]
            }
          ]
        },
        ...
      },
      "dictionary": {
        "af": {
          "name": "Afrikaans",
          "nativeName": "Afrikaans",
          "dir": "ltr",
          "translations": [
            {
              "name": "English",
              "nativeName": "English",
              "dir": "ltr",
              "code": "en"
            }
          ]
        },
      ...
      }
    }
  ]
}

Detect endpoint

Usage

translator.detect({
  text: ['Bonjour']
}).then(detection => {
  console.log(JSON.stringify({ detection }, null, 2))
});

Result

{
  "detection": [
    {
      "language": "fr",
      "score": 1,
      "isTranslationSupported": true,
      "isTransliterationSupported": false
    }
  ]
}

Translate endpoint

Usage

translator.translate({
  text: ['Bonjour'],
  to: "en"
}).then(translation => {
  console.log(JSON.stringify({ translation }, null, 2))
});

Result

{
  "translation": [
    {
      "detectedLanguage": {
        "language": "fr",
        "score": 1
      },
      "translations": [
        {
          "text": "Hello",
          "to": "en"
        }
      ]
    }
  ]
}

Transliterate endpoint

Usage

translator.transliterate({
  text: ["こんにちは"],
  language: "ja",
  fromScript: "Jpan",
  toScript: "Latn",
}).then(transliteration => {
  console.log(JSON.stringify({ transliteration }, null, 2))
});

Result

{
  "transliteration": [
    {
      "text": "Kon'nichiwa",
      "script": "Latn"
    }
  ]
}