Giter Club home page Giter Club logo

google-translate-api's Introduction

google-translate-api

Actions Status NPM version license

A free and unlimited API for Google Translate for Node.js.

In version 9+ library was fully rewritten. For legacy documentation please see legacy branch.

DISCLAIMER! To be 100% legal please use official Google Translate API. This project is mainly for pet projects and prototyping.

Contents

Features

Installation

npm install @vitalets/google-translate-api

Usage

Node.js

import { translate } from '@vitalets/google-translate-api';

const { text } = await translate('Привет, мир! Как дела?', { to: 'en' });

console.log(text) // => 'Hello World! How are you?'

React-native

Since react-native has full support of fetch API translation works the same way as in Node.js.

Web pages

This library does not work inside web pages because translate.google.com does not provide CORS headers allowing access from other domains.

Browser extensions

Although library does not work in regular web pages it can be used in browser extensions. Extensions background and popup pages are not limited with same origin policy. To use translation API you should do the following:

  1. Add host permissions to manifest.json:

    + "host_permissions": [
    +    "https://translate.google.com/"
    +  ]
  2. Import translate as usual in background or popup script:

    // background.js
    import { translate } from '@vitalets/google-translate-api';
    
    const { text } = await translate('Привет мир');
    
    console.log(text);
  3. Bundle code (for example with webpack):

    // webpack.config.js
    module.exports = {
      mode: 'development',
      entry: './background.js',
      output: {
        filename: 'bundle.js',
      },
    };

Limits

Google Translate has request limits. If too many requests are made from the same IP address, you will get a TooManyRequestsError (code 429). You can use proxy to bypass it:

import { translate } from '@vitalets/google-translate-api';
import { HttpProxyAgent } from 'http-proxy-agent';

const agent = new HttpProxyAgent('http://103.152.112.162:80');
const { text } = await translate('Привет, мир!', {
  to: 'en',
  fetchOptions: { agent },
});

See [examples/with-proxy.ts] for more details.

Available proxy list you can find here (with anonymous in *Anonymity and yes in Google columns).

Common pattern for selecting proxy is following:

  try {
    const { text } = await translate('Привет, мир!', {
      to: 'en',
      fetchOptions: { agent },
    });
  } catch (e) {
    if (e.name === 'TooManyRequestsError') {
      // retry with another proxy agent
    }
  }

See #107 for discussion.

API

translate(text: string, options?: Options): Promise<Response>

Parameters

  • text (string) - The text to be translated
  • options (object)
    • from (string) - The language of text. Must be auto or one of the supported languages. Default: auto
    • to (string) - The language in which the text should be translated. Must be one of the supported languages. Default: auto
    • host (string) - Google translate host to be used in API calls. Default: translate.google.com
    • fetchOptions (object) - Additional fetch options passed into request.

Response

  • text (string) – The translated text.
  • raw (object) - Raw responspe from the API. Contains sentences, detected original language and transliteration. Example response.

Related projects

License

MIT © Matheus Fernandes, forked and maintained by Vitaliy Potapov.

Buy Me A Coffee

google-translate-api's People

Contributors

adam-clrk avatar aidanwelch avatar arthurlacoste avatar ciiiii avatar dougley avatar jukeboxrhino avatar matheuss avatar noname001 avatar olavoparno avatar rawr51919 avatar tgyou avatar tobiasmuehl avatar usrtax avatar vitalets avatar vkedwardli avatar xfslove avatar yuler avatar zihadmahiuddin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-translate-api's Issues

[v5] batch-style still has a text limit of 5000 chars

There is still a text limit in batch-style RPC mode from v5.

If the character length exceeds 5000 characters, an error will occur:

TypeError: Cannot read property '1' of null
Url: https://translate.google.com/_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&f.sid=3349740657455987534&bl=boq_translate-webserver_20210128.12_p0&hl=en-US&soc-app=1&soc-platform=1&soc-device=1&_reqid=9513&rt=c
    at ....../node_modules/@vitalets/google-translate-api/index.js:90:21
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'BAD_NETWORK'
}

It happens with this line:

if (json[1][0][0][5] === undefined) {

BAD_REQUEST?

I'm getting this error on my second try (first one worked - I believe):

Error
at C:\mealyet\support\node_modules\google-translate-api\index.js:105:17
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 'BAD_REQUEST'
}

I see all tests failed. Does it mean this component is no more working?

Doesn't work in browser

Hi,

I've tried to run it in a webapp (Vue) and if I use:
const translate = require("@vitalets/google-translate-api");
and launch it, I immediately get an error:
cannot read property 'tostring' of undefined from graceful-fs
What I've read is that

Alright, unfortunately fs-extra won't work in web, as it is based on Node. You can send a request from you web app to your Node server, which handles then your folder structure on your server.

From: jprichardson/node-fs-extra#583 (comment)

Is there any workaround available?

Thanks in advance.

Access type of any word that is being translated

I want to get all types of any word that i want to translate, if i use for example "good", i want to get all types of this word like: adverb,noun,adjective etc...
The object has a property raw but without key, so it is there any easy way to access them?

Error! Unable to issue local certificate

Hi,

While using it in a server, I get the error 'Unable to issue local certificate'.

I know it is not an issue with this package. But could you help with this in case you have come across such errors before?

consistent 403 forbidden

Hello @vitalets,
Thank you for this tool that I've been regularly using for a year now.
It looks like the api has changed recently, Travis has shown 403 from server for a week, since build #832.
Regards,
PK

how to disable auto capital

I translated this sentence from Chinese to English like {taskCode} | {qcConfigName}的质检报告通过失败. I got a translate sentence that is {taskCode} | {qcConfigName}'s quality report failed from google translate in website(https://translate.google.com/). But i got a sentence that is {TaskCode} | {qcConfigName} inspection report by failure in @vitalets/google-translate-api.
Can i get a result without first letter is capital like google translate website that .

problem when deploy in heroku

When I run in the local environment, there is no problem, but when I push the source code onto the heroku server, I get this error:
2020-02-24T16:54:45.510877+00:00 app[web.1]: at /app/node_modules/google-translate-
api/index.js:105:17
2020-02-24T16:54:45.510878+00:00 app[web.1]: at processTicksAndRejections (internal
/process/task_queues.js:97:5) {
2020-02-24T16:54:45.510878+00:00 app[web.1]: code: 'BAD_REQUEST'
2020-02-24T16:54:45.510879+00:00 app[web.1]: }
2020-02-24T16:54:45.511006+00:00 app[web.1]: Error
2020-02-24T16:54:45.511008+00:00 app[web.1]: at /app/node_modules/google-translate-
api/index.js:105:17

2020-02-24T16:54:45.511009+00:00 app[web.1]: at processTicksAndRejections (internal
/process/task_queues.js:97:5) {
2020-02-24T16:54:45.511009+00:00 app[web.1]: code: 'BAD_REQUEST'
2020-02-24T16:54:45.511009+00:00 app[web.1]: }
Please help, thanks.

About the languages.js

the

{
    'zh': 'Chinese (Simplified)',
    'zh-cn': 'Chinese (Simplified)',
    'zh-tw': 'Chinese (Traditional)'
}

are not working when the key in view url(the translate api works with the lowercase key, but the view url not works).

eg:
https://translate.google.com/#view=home&op=translate&sl=en&tl=zh-cn&text=hello
the view will not shown the translation, but tl=zh-CN works.

its case sensitive. seems only support zh-CN, zh-TW.

I think update those key to uppercase is better.

XO Updated

XO has been updated from the version this API is currently using 0.16.0 to 0.28.1

in V0.18.0 it added in 21 new rules: (https://github.com/xojs/xo/releases/tag/v0.18.0)
Unicorn plugin: sindresorhus/[email protected]
no-array-instanceof
no-new-buffer
no-hex-escape
number-literal-case
escape-case
prefer-starts-ends-with
custom-error-definition
type-error
AVA plugin: avajs/eslint-plugin-ava@a0156f1
no-async-fn-without-await
no-duplicate-modifiers

When you update this dependency to 0.28.0 or even past 0.17.0 it breaks the testing in travis, but the api still works in the deployment i use, is there anyway you will be able to update the XO Dependancy and the test to use the latest version.

Response code 503 (Service Unavailable)

I got issue above when call from inside Google VM instance. It will work again after 1-2 days.

Response code 503 (Service Unavailable)\nUrl: https://translate.google.com/translate_a/single?client=t&sl=en&tl=vi&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=0&tsel=0&kc=7&q=32434&tk=560583.924797","stack":"HTTPError: Response code 503 (Service Unavailable)\n at stream.catch.then.data (/source/node_modules/got/index.js:123:13)\n at tryCatcher (/source/node_modules/bluebird/js/release/util.js:16:23)\n at Promise._settlePromiseFromHandler (/source/node_modules/bluebird/js/release/promise.js:512:31)\n at Promise._settlePromise (/source/node_modules/bluebird/js/release/promise.js:569:18)\n at Promise._settlePromise0 (/source/node_modules/bluebird/js/release/promise.js:614:10)\n at Promise._settlePromises (/source/node_modules/bluebird/js/release/promise.js:694:18)\n at _drainQueueStep (/source/node_modules/bluebird/js/release/async.js:138:12)\n at _drainQueue (/source/node_modules/bluebird/js/release/async.js:131:9)\n at Async._drainQueues (/source/node_modules/bluebird/js/release/async.js:147:5)\n at Immediate.Async.drainQueues (/source/node_modules/bluebird/js/release/async.js:17:14)\n at Immediate.args.(anonymous function) [as _onImmediate] (/usr/lib/node_modules/pm2/node_modules/event-loop-inspector/index.js:138:29)\n at runCallback (timers.js:705:18)\n at tryOnImmediate (timers.js:676:5)\n at processImmediate (timers.js:658:5)","host":"translate.google.com","hostname":"translate.google.com","method":"GET","path":"/translate_a/single?client=t&sl=en&tl=vi&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=0&tsel=0&kc=7&q=32434&tk=560583.924797","statusCode":503,"statusMessage":"Service Unavailable","code":"BAD_REQUEST"

Could I use this library on Ionic 4 on a Typescript file?

Hi,

First of all, thanks for such nice library, i'm looking for translate once click a button on ionic 4, but i don't know if it works like that, i'm a newbie on this.

UPDATED

I have errors:

[ng] ERROR in ./node_modules/@vitalets/google-translate-token/node_modules/got/index.js
[ng] Module not found: Error: Can't resolve './package' in '.................../node_modules/@vitalets/google-translate-token/node_modules/got'
[ng] ERROR in ./node_modules/osenv/osenv.js
[ng] Module not found: Error: Can't resolve 'child_process' in '....................../node_modules/osenv'
[ng] ERROR in ./node_modules/got/source/utils/get-body-size.js
[ng] Module not found: Error: Can't resolve 'fs' in '.................../node_modules/got/source/utils'
[ng] ERROR in ./node_modules/graceful-fs/graceful-fs.js
[ng] Module not found: Error: Can't resolve 'fs' in '........................../node_modules/graceful-fs'
[ng] ERROR in ./node_modules/mkdirp/index.js
[ng] Module not found: Error: Can't resolve 'fs' in '................................./node_modules/mkdirp'
[ng] ERROR in ./node_modules/got/source/utils/timed-out.js
[ng] Module not found: Error: Can't resolve 'net' in '......................./node_modules/got/source/utils'

Thank you so much

.forEach error of null

Please look at this issue for reference.

Essentially specific words trigger the .forEach error, not links as you said before

If you use the word "Good" and translate that to spanish from english the error shall be thrown and no translation shall be provided. These words or phrases which result in the dropping of the translation due to an empty value in the arrays is causing these issues and I have no possible idea as to why this would occur.

Any ideas on why and how to fix it? @vitalets @vkedwardli

Question: Proxy

Might be a really dumb question but, Where do you put the proxy code. at what point.

Nonsense generated for haw (wrong translation)

const translate = require('@vitalets/google-translate-api');

var text = 'Ia hala ana mai o ka waa o Pele, ia wa i hoouna mai ai o Kahinalii ka makuahine, i ke kai hoee nui a ka launa ole, a lewa ana ka waa o Honuaiakea iluna o ka halehale hanupanupa kuhoho a kawehaweha o ke kai. Ua huahuai ae la na mapuna o ke kai ma lalo ae o ka papaku o ka moana, hakikili ka ua mai ka lani mai. Olaolapa ka uwela i ka lewa uli, nakolokolo ikuwa ka leo papaaina o ka hekili, huikau ka lewa nuu, ka lewa lalo. Auwe! He ino!!';
translate(text, {from: 'haw', to: 'en'}).then(res => {
console.log(res.text);
//console.log(res.from.language.iso);
}).catch(err => {
console.error(err);
});


$ node translate.js
The youngest birdmen came to whom there, the whole drivenaka had ate fish, and in the land of the sea Shell.All the board of the sea of the sea became the bottom of the sea floor, the feature of the sky.The air, Do otherwise social, Judge Mount Hords, communions to the air Nuunu.Wow!Is a bad !!


When pasted into translate.google.com:

When Pele's canoe passed, the mother sent Kahinalii to paddle a great and incompatible paddle, and the canoe from Honuaiakea flew over the mysterious building and the depths of the sea. The waves of the sea poured forth beneath the sea floor, and the rain from heaven thundered. The lightning flashed in the dark sky, the table sound of thunder roared, the sky above and the sky below were confused. Alas! It's bad !!

Translating to Traditional Chinese translates to Simplified Chinese instead

A minor bug I noticed after PR #6. It's that the value of text.from.language.iso is undefined when you auto-translate from Simplified or Traditional Chinese (the way text.from.language.iso is generated might have to be tweaked to fix this bug).
Example: Translating 你好 should result in text.from.language.iso being one of the language codes for Chinese Simplified, but it returns undefined instead when translated.

Punjabi is using the wrong language code, Simplified Chinese doesn't use both the 'zh' and 'zh-cn' language codes, and Hebrew doesn't use both the 'he' and 'iw' language codes in languages.js (China also cannot use this library either, so this will fix that as well)

The language code for Punjabi is labelled as ma when it should be pa. ma will just give the source string when trying to translate into Punjabi, while pa will give the proper Punjabi translation. Hebrew translations are supported under both the he and iw language codes, but only iw is supported in this module (same goes for Simplified Chinese where both zh and zh-cn language codes are supported for translations, but only zh-cn is supported in this module). China also has the main Translate URL (translate.google.com) banned, so allowing for anyone to use any language Translate URL they wish will fix this issue. A PR has been created to allow these issues to be fixed (PRs #6, #7, and vitalets/google-translate-token#2). These are all long-standing issues that have persisted since the days of the original repo (see matheuss#48, matheuss#59, matheuss#60, matheuss#62, matheuss#68, and matheuss/google-translate-token#10 for more details on this). (matheuss#48, matheuss#59, matheuss#62, and matheuss#68 have been fixed already).

429 Too Many Requests

Using DiscordJs i'm mapping through all channels to translate a message to different languages at the same time. This obv. leads to HTTP 429. It worked for a week, but now it stoped working. Looking at the code i can see it throws and i start to wonder why it was working all the time in the first place. Do you have any advice for me, how to deal with this?

Also can you add an option to make it not translate certain pattern? For me it would be everything between < >. Thanks.

Issue in using Chinese Traditional and Chinese Simplified

turn zh-CN and zh-TW in languages.js into lowerCase because getCode function in language.js converts the parameter into lowerCase but while matching it in langs object, It can't find because zh-CN and zh-TW are in upper case.

Support for typescript?

I really like this package but I see that it does not have the "types" of TypeScript and I do not get any method. I would very much like it to have support.

Unable to resolve module `querystring`

i am getting that error
bundling failed: Error: Unable to resolve modulequerystringfromE:\React Native\react-native-multi-language-app\node_modules@vitalets\google-translate-api\index.js: Module querystring does not exist in the Haste module map

TKK generated

Hey.

Did you manage to figure out how TKK is generated?

var code = res.body.match(/TKK='.*?';/g);

TKK= not found in HTML https://translate.google.com

tkk

Where does TKK come from?

Maybe this: tkk:'434303.3040823967'

High severity security vulnerabilities

A recent NPM audit found that one of this package's dependencies (dot-prop) is vulnerable to prototype pollution. It appears that the version of dot-prop used in this package is outdated, resulting in this issue.
I am currently using the latest version of this package (v 3.0.0)
I'm wondering if there's a fix already available or if one needs to be released.

NPM audit screenshot

translation quality

Is there any way to control the quality of the translation?
I have the feeling that my translations are of very bad quality, especially since I reactivated my module a few days ago after several months.
translate.google.com gives much better results.

Sample:
"In 1980, a Las Vegas hospital suspended workers for betting on when patients would die!"

translate.google.com:
"1980 suspendierte ein Krankenhaus in Las Vegas Arbeiter, weil sie darauf gewettet hatten, wann Patienten sterben würden!" (very good)

My App:
translate(result, { from: 'en', to: 'de' }) .then(function(result) { console.log(result.text); }).catch(function(e) { console.log("[MMM-rfacts] Translation ERROR! Translation failed, will fall back to English."); });

Result:
"Im Jahr 1980 suspendierten ein Las Vegas Krankenhausmitarbeiter für Wetten auf, wenn Patienten sterben würden!" (bad quality)

Error 413: Request Entity too large

Hi,

First of all, a great thanks for creating this npm package and it works for most cases.

There is but one issue I observed while using it - 413: Request Entity too large. This happened in some cases

I am unable to understand why this error occurs and how to avoid it.

Also is there any limitation on usage - such as number of requests or frequency of requests that I should know?

Would appreciate if you could help with this

Regards,
Gaureesh

Support react-native

Currently library works only in Node.js, because it replies on packages like fs, configstore etc. It does not work in React Native out of box but technically it is possible.

It would be great to to add build for react native where usage of fs and configstore are replaced with RN asyncStorage api.

Related issues:

Extra blank space when translate markdown content

  • When I try to translate the markdown, it returns extra blank space between []() and ![](), that are common format to add link and image in markdown.
  • Content to be translated:
## 中文标题

[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/g-canvas-linedash-1zuzx)

[https://github.com/antvis/g/blob/4.x/packages/g-canvas/src/util/draw.ts#L22](https://github.com/antvis/g/blob/4.x/packages/g-canvas/src/util/draw.ts#L22)
  • Translated content :
## Chinese title\n\n[! [Edit on CodeSandbox] (https://codesandbox.io/static/img/play-codesandbox.svg)] (https://codesandbox.io/s/g-canvas-linedash-1zuzx)\n\n[Https://github.com/antvis/g/blob/4.x/packages/g-canvas/src/util/draw.ts#L22](https://github.com/antvis/g/blob/ 4.x / packages / g-canvas / src / util / draw.ts # L22)

While executing translate("Hello Welcome to my world",{to:"ar"}).then((transText) =>{ console.log(transText) })

./node_modules/@vitalets/google-translate-token/node_modules/got/index.js
Module not found: Error: Can't resolve './package' in 'C:\Users\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got'
resolve './package' in 'C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got'
using description file: C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package.json (relative path: .)
using description file: C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package.json (relative path: ./package)
no extension
C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package doesn't exist
.ts
C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package.ts doesn't exist
.js
C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package.js doesn't exist
as directory
C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package doesn't exist
[C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package]
[C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package.ts]
[C:\CypressProject\node_modules@vitalets\google-translate-token\node_modules\got\package.js]
@ ./node_modules/@vitalets/google-translate-token/node_modules/got/index.js 19:12-32
@ ./node_modules/@vitalets/google-translate-token/index.js
@ ./node_modules/@vitalets/google-translate-api/index.js
@ ./cypress/integration/pages/SearchPage.ts
@ ./cypress/integration/stepdefinitions/HomePageStepDef.ts
@ ./cypress/integration/features/SearchE2E.feature
@ multi ./cypress/integration/features/SearchE2E.feature

./node_modules/got/source/utils/timed-out.js
Module not found: Error: Can't resolve 'net' in 'C:\CypressProject\node_modules\got\source\utils'
resolve 'net' in 'C:\CypressProject\node_modules\got\source\utils'
Parsed request is a module
using description file: C:\CypressProject\node_modules\got\package.json (relative path: ./source/utils)
resolve as module
\CypressProject\node_modules\got\source\utils\node_modules doesn't exist or is not a directory
\CypressProject\node_modules\got\source\node_modules doesn't exist or is not a directory
\CypressProject\node_modules\node_modules doesn't exist or is not a directory
\node_modules doesn't exist or is not a directory
\node_modules doesn't exist or is not a directory
\node_modules doesn't exist or is not a directory
\node_modules doesn't exist or is not a directory
\node_modules doesn't exist or is not a directory
looking for modules in C:\CypressProject\node_modules
using description file: C:\CypressProject\package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
looking for modules in \node_modules
using description file: \package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\CypressProject\package.json (relative path: ./node_modules/net)
no extension
Field 'browser' doesn't contain a valid alias configuration
using description file: \package.json (relative path: ./node_modules/net)
no extension
Field 'browser' doesn't contain a valid alias configuration
looking for modules in C:\CypressProject\node_modules\got\node_modules
using description file: C:\CypressProject\node_modules\got\package.json (relative path: ./node_modules)
using description file: C:\CypressProject\node_modules\got\package.json (relative path: ./node_modules/net)
no extension
C:\CypressProject\node_modules\got\node_modules\net doesn't exist
C:\CypressProject\node_modules\net doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
\node_modules\net doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
.ts
C:\CypressProject\node_modules\got\node_modules\net.ts doesn't exist
C:\CypressProject\node_modules\net.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
\node_modules\net.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
.js
C:\CypressProject\node_modules\got\node_modules\net.js doesn't exist
C:\CypressProject\node_modules\net.js doesn't exist
\node_modules\net.js doesn't exist
as directory
C:\CypressProject\node_modules\got\node_modules\net doesn't exist
as directory
C:\CypressProject\node_modules\net doesn't exist
as directory
\node_modules\net doesn't exist
[C:\CypressProject\node_modules\got\source\utils\node_modules]
[C:\CypressProject\node_modules\got\source\node_modules]
[C:\CypressProject\node_modules\node_modules]
[C:\node_modules]
[C:\node_modules]
[C:\node_modules]
[C:\Users\node_modules]
[C:\node_modules]
[C:\CypressProject\node_modules\got\node_modules\net]
[C:\CypressProject\node_modules\net]
[\node_modules\net]
[C:\CypressProject\node_modules\got\node_modules\net.ts]
[C:\CypressProject\node_modules\net.ts]
[\node_modules\net.ts]
[C:\CypressProject\node_modules\got\node_modules\net.js]
[C:\CypressProject\node_modules\net.js]
[\node_modules\net.js]
@ ./node_modules/got/source/utils/timed-out.js 2:12-26
@ ./node_modules/got/source/request-as-event-emitter.js
@ ./node_modules/got/source/as-promise.js
@ ./node_modules/got/source/create.js
@ ./node_modules/got/source/index.js
@ ./node_modules/@vitalets/google-translate-api/index.js
@ ./cypress/integration/pages/SearchPage.ts
@ ./cypress/integration/stepdefinitions/HomePageStepDef.ts
@ ./cypress/integration/features/SearchE2E.feature
@ multi ./cypress/integration/features/SearchE2E.feature

./node_modules/defer-to-connect/dist/index.js
Module not found: Error: Can't resolve 'tls' in 'C:\CypressProject\node_modules\defer-to-connect\dist'
resolve 'tls' in 'C:\CypressProject\node_modules\defer-to-connect\dist'
Parsed request is a module
using description file: C:\CypressProject\node_modules\defer-to-connect\package.json (relative path: ./dist)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
C:\CypressProject\node_modules\defer-to-connect\dist\node_modules doesn't exist or is not a directory
C:\CypressProject\node_modules\defer-to-connect\node_modules doesn't exist or is not a directory
C:\CypressProject\node_modules\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
C:\Users\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
looking for modules in C:\CypressProject\node_modules
using description file: C:\CypressProject\package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
looking for modules in \node_modules
using description file: \package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\CypressProject\package.json (relative path: ./node_modules/tls)
no extension
Field 'browser' doesn't contain a valid alias configuration
using description file: \package.json (relative path: ./node_modules/tls)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\CypressProject\node_modules\tls doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
\node_modules\tls doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\CypressProject\node_modules\tls.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
\node_modules\tls.ts doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\CypressProject\node_modules\tls.js doesn't exist
\node_modules\tls.js doesn't exist
as directory
C:\CypressProject\node_modules\tls doesn't exist
as directory
\node_modules\tls doesn't exist
[C:\CypressProject\node_modules\defer-to-connect\dist\node_modules]
[C:\CypressProject\node_modules\defer-to-connect\node_modules]
[C:\CypressProject\node_modules\node_modules]
[C:\node_modules]
[C:\node_modules]
[C:\node_modules]
[C:\Users\node_modules]
[C:\node_modules]
[C:\CypressProject\node_modules\tls]
[\node_modules\tls]
[C:\CypressProject\node_modules\tls.ts]
[\node_modules\tls.ts]
[C:\CypressProject\node_modules\tls.js]
[\node_modules\tls.js]
@ ./node_modules/defer-to-connect/dist/index.js 3:14-28
@ ./node_modules/@szmarczak/http-timer/source/index.js
@ ./node_modules/got/source/request-as-event-emitter.js
@ ./node_modules/got/source/as-promise.js
@ ./node_modules/got/source/create.js
@ ./node_modules/got/source/index.js
@ ./node_modules/@vitalets/google-translate-api/index.js
@ ./cypress/integration/pages/SearchPage.ts
@ ./cypress/integration/stepdefinitions/HomePageStepDef.ts
@ ./cypress/integration/features/SearchE2E.feature
@ multi ./cypress/integration/features/Search.feature

Return the converted text

Hi,

This api is really helpful.
I have a question.

The translation is success based on the console.log(). Is there a way to return the converted text?

Thanks. Help is highly appreciated.

Type definitions

Hey mister, firstly thanks for the lib. It is awesome. Secondly, could you add these type definitions in your project?

Just copy it to a file index.d.ts in case you don't know already.

Thank you again!

export = googleTranslateApi

declare function googleTranslateApi(
  query: string,
  opts?: googleTranslateApi.IOptions,
): Promise<googleTranslateApi.ITranslateResponse>

declare namespace googleTranslateApi {
  export interface IOptions {
    from?: string
    to?: string
  }

  export interface ITranslateLanguage {
    didYouMean: boolean
    iso: string
  }

  export interface ITranslateText {
    autoCorrected: boolean
    value: string
    didYouMean: boolean
  }

  export interface ITranslateResponse {
    text: string
    pronunciation: string
    from: {
      language: ITranslateLanguage
      text: ITranslateText
    }
    raw: string
  }

  export enum language {
    'zh-CN' = 'Chinese (Simplified)',
    'zh-TW' = 'Chinese (Traditional)',
    af = 'Afrikaans',
    am = 'Amharic',
    ar = 'Arabic',
    auto = 'Automatic',
    az = 'Azerbaijani',
    be = 'Belarusian',
    bg = 'Bulgarian',
    bn = 'Bengali',
    bs = 'Bosnian',
    ca = 'Catalan',
    ceb = 'Cebuano',
    co = 'Corsican',
    cs = 'Czech',
    cy = 'Welsh',
    da = 'Danish',
    de = 'German',
    el = 'Greek',
    en = 'English',
    eo = 'Esperanto',
    es = 'Spanish',
    et = 'Estonian',
    eu = 'Basque',
    fa = 'Persian',
    fi = 'Finnish',
    fr = 'French',
    fy = 'Frisian',
    ga = 'Irish',
    gd = 'Scots Gaelic',
    gl = 'Galician',
    gu = 'Gujarati',
    ha = 'Hausa',
    haw = 'Hawaiian',
    he = 'Hebrew',
    hi = 'Hindi',
    hmn = 'Hmong',
    hr = 'Croatian',
    ht = 'Haitian Creole',
    hu = 'Hungarian',
    hy = 'Armenian',
    id = 'Indonesian',
    ig = 'Igbo',
    is = 'Icelandic',
    it = 'Italian',
    iw = 'Hebrew',
    ja = 'Japanese',
    jw = 'Javanese',
    ka = 'Georgian',
    kk = 'Kazakh',
    km = 'Khmer',
    kn = 'Kannada',
    ko = 'Korean',
    ku = 'Kurdish (Kurmanji)',
    ky = 'Kyrgyz',
    la = 'Latin',
    lb = 'Luxembourgish',
    lo = 'Lao',
    lt = 'Lithuanian',
    lv = 'Latvian',
    mg = 'Malagasy',
    mi = 'Maori',
    mk = 'Macedonian',
    ml = 'Malayalam',
    mn = 'Mongolian',
    mr = 'Marathi',
    ms = 'Malay',
    mt = 'Maltese',
    my = 'Myanmar (Burmese)',
    ne = 'Nepali',
    nl = 'Dutch',
    no = 'Norwegian',
    ny = 'Chichewa',
    pa = 'Punjabi',
    pl = 'Polish',
    ps = 'Pashto',
    pt = 'Portuguese',
    ro = 'Romanian',
    ru = 'Russian',
    sd = 'Sindhi',
    si = 'Sinhala',
    sk = 'Slovak',
    sl = 'Slovenian',
    sm = 'Samoan',
    sn = 'Shona',
    so = 'Somali',
    sq = 'Albanian',
    sr = 'Serbian',
    st = 'Sesotho',
    su = 'Sundanese',
    sv = 'Swedish',
    sw = 'Swahili',
    ta = 'Tamil',
    te = 'Telugu',
    tg = 'Tajik',
    th = 'Thai',
    tl = 'Filipino',
    tr = 'Turkish',
    uk = 'Ukrainian',
    ur = 'Urdu',
    uz = 'Uzbek',
    vi = 'Vietnamese',
    xh = 'Xhosa',
    yi = 'Yiddish',
    yo = 'Yoruba',
    zu = 'Zulu',
  }
}

Creating /.config folder in root

This is occured when it is deployed in our server, the library is creating a .config folder
This is the error displayed
Error: EACCES: permission denied, mkdir '/.config'
Which is not allowed by our server.

Add test case for translating without an internet connection

Could this be reasonably implemented in test.js? It'll require temporarily disabling (or simulating the disabling of) the internet access to test.js when this is ran in order for this test case to work properly. I've attempted to code this test case in for PR #12.
There's already a todo test case in test.js for this:

test.todo('try to translate some text without an internet connection');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.