Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google-translate-api-nodejs-client

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-translate-api-nodejs-client - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

5

availableLanguages.js

@@ -1,6 +0,5 @@

var config = require('./config'),
request = require('request'),
var request = require('request'),
Logger = require('logb').getLogger(module.filename);
var API_KEY = config.GOOGLE_TRANSLATE_API_KEY,
var API_KEY = process.env.GOOGLE_TRANSLATE_API_KEY,
URL = 'https://www.googleapis.com/language/translate/v2/languages?key=' + API_KEY;

@@ -7,0 +6,0 @@

24

google-translate-api-nodejs-client.js
var request = require('request'),
config = require('./config'),
Logger = require('logb').getLogger(module.filename),

@@ -7,10 +6,16 @@ Entities = require('html-entities').AllHtmlEntities,

var API_KEY = config.GOOGLE_TRANSLATE_API_KEY,
URL = 'https://www.googleapis.com/language/translate/v2';
function translate(opts, cb) {
var GoogleTranslateApi = module.exports = function GoogleTranslateApi(options) {
this.API_KEY = options.API_KEY;
this.URL = 'https://www.googleapis.com/language/translate/v2';
}
GoogleTranslateApi.prototype.translate = function translate(opts, cb) {
var self = this;
request.post({
url: URL,
url: self.URL,
headers: {

@@ -20,3 +25,3 @@ 'X-HTTP-Method-Override': 'GET'

form: {
key: API_KEY,
key: self.API_KEY,
q: opts.text,

@@ -34,3 +39,5 @@ source: opts.source,

}
body = JSON.parse(body);
translation = body.data.translations[0].translatedText;

@@ -45,9 +52,8 @@ translation = entities.decode(translation);

module.exports.translate = translate;
module.exports.fromGermanToEnglish = function(text, cb) {
GoogleTranslateApi.prototype.fromGermanToEnglish = function fromGermanToEnglish(text, cb) {
Logger.info('Translating from German to English...');
translate({
this.translate({
source: 'de',

@@ -54,0 +60,0 @@ target: 'en',

{
"name": "google-translate-api-nodejs-client",
"version": "1.0.1",
"version": "1.0.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "google-translate-api-nodejs-client.js",

@@ -8,12 +8,18 @@ # google-translate-api-nodejs-client

```
translate({
source:'en',
target:'ge',
q:'...text is here...'
}, function(err,translation){
var GoogleTranslateApi=require('google-translate-api-nodejs-client');
new GoogleTranslateApi({
API_KEY:'...'
})
.translate({
source:'en',
target:'ge',
q:'...text is here...'
}, function(err,translation){
// translation is a string representing the output translation
// original response would be in html, this client converts the html to a proper text string
// translation is a string representing the output translation
// original response would be in html, this client converts the html to a proper text string
});
});
```

@@ -25,3 +31,3 @@

cd google-translate-api-nodejs-client
node availableLanguages.js
GOOGLE_TRANSLATE_API_KEY=... node availableLanguages.js
```

@@ -19,4 +19,2 @@ var expect = require('chai').expect,

});

@@ -26,9 +24,16 @@

if (!process.env.GOOGLE_TRANSLATE_API_KEY) {
throw new Error('Please specify the env variable GOOGLE_TRANSLATE_API_KEY');
return;
}
GoogleTranslateApiClient.fromGermanToEnglish(germanText, function(err, translation) {
expect(err).to.be.null;
expect(translation).to.be.not.undefined;
expect(translation).to.be.eql(germanTextEnglishTranslation);
done();
});
new GoogleTranslateApiClient({
API_KEY: process.env.GOOGLE_TRANSLATE_API_KEY
})
.fromGermanToEnglish(germanText, function(err, translation) {
expect(err).to.be.null;
expect(translation).to.be.not.undefined;
expect(translation).to.be.eql(germanTextEnglishTranslation);
done();
});

@@ -35,0 +40,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc