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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mattbrannon/translator

v1.0.0

Published

This project aims to combine the functionality of multiple translation services into a single API. Each translation service requires an API key. You can get an API key for each translator at the following links:

Readme

Translator

This project aims to combine the functionality of multiple translation services into a single API. Each translation service requires an API key. You can get an API key for each translator at the following links:

Note - These are listed in order of most difficult to easiest (in my opinion). Google Translate requires you to create a Google Cloud account, create a project and enable the Translate API. Microsoft Translate requires you to create an Azure account, create a Cognitive Services resource and enable the Translator Text API. DeepL Translate only requires you to create an account and generate an API key.

You don't have to get an API key for every translation service. For example if you only wanted to use the DeepL Translator, you need only supply the DeepL API key. If you wanted to use all three services, you would need to supply all three API keys.

Table of Contents

Installation

npm install @mattbrannon/translator

Usage

import { makeTranslators } from "@mattbrannon/translator";
const translators = makeTranslators({
  google: process.env.GOOGLE_API_KEY,
  microsoft: process.env.MICROSOFT_API_KEY,
  deepL: process.env.DEEPL_API_KEY,
});

(async () => {
  const { google, microsoft, deepL } = translators;

  const text = ["Hello World!", "Goodbye World!"];
  const target = "es";

  const googleTranslation = await google.translate({ text, target });
  const microsoftTranslation = await microsoft.translate({ text, target });
  const deepLTranslation = await deepL.translate({ text, target });

  console.log({
    googleTranslation,
    microsoftTranslation,
    deepLTranslation,
  });
})();

API

Each translator has a translate method that takes an object with the following properties:

  • text - An array of strings or a single string to be translated.
  • target - The language code of the language to translate to.
  • source - The language code of the language to translate from. This is optional. If not provided each translator will attempt to detect the source language.
  • options - An object containing additional options. This is optional. See below for more details.

The options object is used set translator specific options as well as options that are common to all translators. The following options are common to all translators:

  • ignore - An array of regular expressions to match words that should be ignored by the translator.
  • join - A boolean value indicating whether the translated text should be joined into a single string.
const text = [
  "She sells seashells 🐚 down by the seashore.",
  "I scream, 😱 you scream, we all scream for 🍨 ice cream.",
];
const target = "es";

const wordsThatStartWithS = /\b[sS]\w+\b/g;
const emoji = /\p{Extended_Pictographic}/gu;

const options = {
  ignore: [wordsThatStartWithS, emoji],
  join: true,
};

await microsoft.translate({ text, target, options });

The following sections describe the differences between each translator.

Google Translate

The google translator has the following additional methods:

  • detectLanguage - Takes an object with a text property and returns the detected language code.
  • getLanguages - Takes an object with an optional target property and returns an array of supported language codes in the specified target language.
const translators = makeTranslators({
  google: process.env.GOOGLE_API_KEY,
});

const { google } = translators;

const detectedLanguage = await google.detectLanguage({ text: "Hello World!" });
const supportedLanguages = await google.getLanguages({ target: "es" });

console.log({
  detectedLanguage,
  supportedLanguages,
});

Microsoft Translate

The microsoft translator has transliteration capabilities in addition to translation. You don't have to do anything special to use transliteration. Just provide a target language code and if transliteration is supported for that language, it will be included in the response.

The microsoft translator has the following additional methods on the languages property:

  • translation - Returns an array of supported language codes for translation.
  • transliteration - Returns an array of supported language codes for transliteration.
  • dictionary - Returns an array of supported language codes for dictionary operations.
const translators = makeTranslators({
  microsoft: process.env.MICROSOFT_API_KEY,
});

const { microsoft } = translators;

const translationLanguages = await microsoft.languages.translation();
const transliterationLanguages = await microsoft.languages.transliteration();
const dictionaryLanguages = await microsoft.languages.dictionary();

console.log({
  translationLanguages,
  transliterationLanguages,
  dictionaryLanguages,
});

DeepL Translate

The deepL translator has the following additional methods:

  • sourceLanguages - Returns an array of valid source language codes.
  • targetLanguages - Returns an array of valid target language codes.
  • usage - Returns an object containing usage statistics for the current billing period.
(async () => {
  const translators = makeTranslators({
    deepL: process.env.DEEPL_API_KEY,
  });

  const { deepL } = translators;

  const sourceLanguages = await deepL.sourceLanguages();
  const targetLanguages = await deepL.targetLanguages();
  const usageStatistics = await deepL.usage();

  console.log({
    sourceLanguages,
    targetLanguages,
    usageStatistics,
  });
})();

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.