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

@hamakh11/free-google-translate-api

v1.0.0

Published

A Node.JS library to consume Google Translate API for free.

Downloads

7

Readme

Google Translate API

A Node.JS library to consume Google Translate for free.

GitHub release Dependencies Known Vulnerabilities license

Feature Highlights

  • Automatically detect source language
  • Automatic spelling corrections
  • Automatic language correction
  • Fast and reliable

Table of Contents

Installation

# Stable version, from npm repository
npm install --save @iamtraction/google-translate

# Latest version, from GitHub repository
npm install --save iamtraction/google-translate

Usage

// If you've installed from npm, do:
const translate = require('@iamtraction/google-translate');

// If you've installed from GitHub, do:
const translate = require('google-translate');

Method: translate(text, options)

translate(text, options).then(console.log).catch(console.error);

| Parameter | Type | Optional | Default | Description | |-|-|-|-|-| | text | String | No | - | The text you want to translate. | | options | Object | - | - | The options for translating. | | options.from | String | Yes | 'auto' | The language name/ISO 639-1 code to translate from. If none is given, it will auto detect the source language. | | options.to | String | Yes | 'en' | The language name/ISO 639-1 code to translate to. If none is given, it will translate to English. | | options.raw | Boolean | Yes | false | If true, it will return the raw output that was received from Google Translate. |

Returns: Promise<Object>

Response Object:

| Key | Type | Description | |-|-|-| | text | String | The translated text. | | from | Object | - | | from.language | Object | - | | from.language.didYouMean | Boolean | Whether or not the API suggest a correction in the source language. | | from.language.iso | String | The ISO 639-1 code of the language that the API has recognized in the text. | | from.text | Object | - | | from.text.autoCorrected | Boolean | Whether or not the API has auto corrected the original text. | | from.text.value | String | The auto corrected text or the text with suggested corrections. Only returned if from.text.autoCorrected or from.text.didYouMean is true. | | from.text.didYouMean | Boolean | Wherether or not the API has suggested corrections to the text | | raw | String | The raw response from Google Translate servers. Only returned if options.raw is true in the request options. |

Examples

From automatic language detection to English:

translate('Tu es incroyable!', { to: 'en' }).then(res => {
  console.log(res.text); // OUTPUT: You are amazing!
}).catch(err => {
  console.error(err);
});

From English to French, with a typo:

translate('Thank you', { from: 'en', to: 'fr' }).then(res => {
  console.log(res.text); // OUTPUT: Je vous remercie
  console.log(res.from.autoCorrected); // OUTPUT: true
  console.log(res.from.text.value); // OUTPUT: [Thank] you
  console.log(res.from.text.didYouMean); // OUTPUT: false
}).catch(err => {
  console.error(err);
});

Sometimes Google Translate won't auto correct:

translate('Thank you', { from: 'en', to: 'fr' }).then(res => {
  console.log(res.text); // OUTPUT: ''
  console.log(res.from.autoCorrected); // OUTPUT: false
  console.log(res.from.text.value); // OUTPUT: [Thank] you
  console.log(res.from.text.didYouMean); // OUTPUT: true
}).catch(err => {
  console.error(err);
});

Extras

If you liked this project, please give it a ⭐ in GitHub.

Credits to matheuss for writing the original version of this library. I rewrote this, with improvements and without using many external libraries, as his library was not actively developed and had vulnerabilities.