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 🙏

© 2026 – Pkg Stats / Ryan Hefner

google-translate-starktech

v0.1.8

Published

Starktech Google Translate API for Node.js

Readme

Google Translate API for Node

A Node.js module for working with the Google Translate API.

Automatically handles bulk translations that exceed the Google Translation API query limit.

Installation

Install via npm

npm install google-translate --save

Usage overview

Require module and pass in your API key (get one here).

var googleTranslate = require('google-translate')(apiKey);

String translation:

googleTranslate.translate('My name is Brandon', 'es', function(err, translation) {
  console.log(translation.translatedText);
  // =>  Mi nombre es Brandon
});

Language detection:

googleTranslate.detectLanguage('Gracias', function(err, detection) {
  console.log(detection.language);
  // =>  es
});

API

Callbacks: All methods take a callback as their last parameter. Upon method completion, callbacks are passed an error if exists (otherwise null), followed by a response object or array: callback(err, data).

Bulk translations: Passing an array of strings greater than 2k characters will be result in multiple concurrent asynchronous calls. Once all calls are completed, the response will be parsed, merged, and passed to the callback. The default maximum concurrent requests is 10. You can override this value by passing in a new limit when you pass in your API key: require('google-translate')(apiKey, concurrentLimit)

Translate

Translate one or more strings.

googleTranslate.translate(strings, source, target, callback)
  • strings: Required. Can be a string or an array of strings
  • source: Optional. Google will autodetect the source locale if not specified. Available languages
  • target: Required. Language to translate to. Available languages
  • callback: Required.

Example: Translate a string to German (de) and autodetect source language

googleTranslate.translate('Hello', 'de', function(err, translation) {
  console.log(translation);
  // =>  { translatedText: 'Hallo', originalText: 'Hello', detectedSourceLanguage: 'en' }
});

Example: Translate an array of English (en) strings to German (de)

googleTranslate.translate(['Hello', 'Thank you'], 'en', 'de', function(err, translations) {
  console.log(translations);
  // =>  [{ translatedText: 'Hallo', originalText: 'Hello' }, ...]
});

Detect language

Detect language of string or each string in an array.

googleTranslate.detectLanguage(strings, callback)
  • strings: Required. Can be a string or an array of strings
  • callback: Required.

Example: Detect language from a string

googleTranslate.detectLanguage('Hello', function(err, detection){
  console.log(detection);
  // =>  { language: "en", isReliable: false, confidence: 0.5714286, originalText: "Hello" }
});

Example: Detect language from an array of strings

googleTranslate.detectLanguage(['Hello', 'Danke'], function(err, detections) {
  console.log(detections);
  // =>  [{ language: "en", isReliable: false, confidence: 0.5714286, originalText: "Hello" }, ...]
});

Get supported languages

Retrieve all languages supported by the Google Translate API.

googleTranslate.getSupportedLanguages(target, callback)
  • target: Optional. If specified, response will include the name of the language translated to the specified target language
  • callback: Required.

Example: Get all supported language codes

googleTranslate.getSupportedLanguages(function(err, languageCodes) {
  console.log(languageCodes);
  // => ['af', 'ar', 'be', 'bg', 'ca', 'cs', ...]
});

Example: Get all supported language codes with language names in German

googleTranslate.getSupportedLanguages('de', function(err, languageCodes) {
  console.log(languageCodes);
  // => [{ language: "en", name: "Englisch" }, ...]
});

Contribute

Forks and pull requests welcome!

TODO

  • Make POST instead of GET requests when query is greater than 2k. Limit for POST is 5k
  • Add tests
  • Design a better way of defining API keys to allow use of multiple Google Translate API keys

Author

Brandon Paton. Email me if you have any questions: [email protected]. Supported by Localize.js.