• Stars
    star
    522
  • Rank 84,811 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

ZOD

This is a decompression bomb (also known as zip of death or zip bomb) designed to crash or render useless the program or system reading it.
362
star
2

WindowsRegistry

Windows Registry Tweaks & Hacks
46
star
3

forkbombs

:(){ :|: };: πŸ’£ Fork bombs (wabbits) in many languages. Spot them before executing any code so that you can prevent yourself from accidentally nuking your device.
JavaScript
38
star
4

WebCord

WebCord is a Discord client that uses WebView to bring Discord's webapp to Desktop for a lightweight Discord experience.
Go
37
star
5

ThePerfectSite

The Perfect Website. It's fast (I mean really FAST). It's responsive. Uses HTML5 and CSS3. Works in all browsers and screen sizes. Well, this is not feasible practically in real-life cases for most of the websites.
HTML
23
star
6

discoIPC

Connect to the local Discord IPC Socket, for features like Rich Presence.
Python
19
star
7

UD513-Udacity

UD513 - Data Structures and Algorithms in Python - Udacity Course
Python
16
star
8

node-trivia-api

❔ A nodejs module for getting trivia questions in all your fancy projects, in a pretty simple way.
JavaScript
7
star
9

Bastion-Site

Old website of Bastion Discord Bot. New website is available at https://bastionbot.org
CSS
6
star
10

read-time

A Node.JS library to estimate the time it will take to read a given text.
JavaScript
5
star
11

cleverbot.js

πŸ—¨ A Node.js Cleverbot API wrapper library. Go make a chat bot in a flash!
JavaScript
4
star
12

DynamicWallpaper

Dyamic Wallpaper support for Windows.
Python
3
star
13

jumpscare

If you are easily scared, this game isn't for you! :)
HTML
3
star
14

matt-daemon

A lightweight HTTP daemon for serving static files. With Matt Daemon, there are no surprises. He just serves.
Python
3
star
15

bitcoin-original

This is the source code of Satoshi Nakamoto's original bitcoin.
C++
3
star
16

fix-windows-update

Fix your issues with Windows Update using a simple script.
PowerShell
3
star
17

BASIC-M6502

πŸ–₯ The original 1978 source code of Microsoft BASIC for 6502 with all original comments, documentation and easter eggs.
3
star
18

DiscordBirthdayCountdown

Countdown to the Birthday of Discord!
JavaScript
3
star
19

hackernews

Hackernews - A social news website focusing on computer science, entrepreneurship, and anything that gratifies one's intellectual curiosity.
JavaScript
3
star
20

Locke

🈯 A simple string internationalization handler for Node.js applications.
TypeScript
3
star
21

WebDevelopement

Web Development tips, tricks & ideas.
JavaScript
2
star
22

c-source-server-query

Source server query library by Valve Software.
C
2
star
23

riddles-rich-presence

An example Riddles game to show the implementation of discoIPC Python package.
Python
2
star
24

Sylvester

Sylvester makes your server a RPG battleground for Cat Showdowns!
TypeScript
2
star
25

go-installer

A seemless way to install Go in linux based systems.
Shell
2
star
26

eol-ender

Fix line endings recursively in all the files in the current directory with a single command!
Python
1
star
27

macOS-Kexts

1
star
28

S-Icons

S Icons v1.0.0
1
star
29

HackerRank

Python
1
star
30

CaptivePortalAutoConnector

[WIP] Automatically connect to captive portal without needed to manually do it every time you connect to the network.
Python
1
star
31

k3rn31p4nic.github.io

HTML
1
star
32

node-extraction

ex.traction.one Node API Wrapper
TypeScript
1
star
33

WebDriverBinariesAPI

[WIP] A small API to allow you to download the latest version of WebDriver Binaries of different browsers.
TypeScript
1
star
34

awesome-declarations

Awesome declarations in various programming languages.
C
1
star
35

SteamProfileResolverAPI

An API to resolve the Steam profile from a Vanity URL. Endpoint: /api/:vanityURL
TypeScript
1
star