Socket
Socket
Sign inDemoInstall

@google-cloud/translate

Package Overview
Dependencies
Maintainers
13
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/translate - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

LICENSE

91

package.json
{
"name": "@google-cloud/translate",
"version": "1.0.0",
"description": "Cloud Translation API Client Library for Node.js",
"version": "1.1.0",
"license": "Apache-2.0",
"author": "Google Inc.",
"description": "Cloud Translation API Client Library for Node.js",
"contributors": [
{
"name": "Burcu Dogan",
"email": "jbd@google.com"
},
{
"name": "Johan Euphrosine",
"email": "proppy@google.com"
},
{
"name": "Patrick Costello",
"email": "pcostell@google.com"
},
{
"name": "Ryan Seys",
"email": "ryan@ryanseys.com"
},
{
"name": "Silvano Luciani",
"email": "silvano@google.com"
},
{
"name": "Stephen Sawchuk",
"email": "sawchuk@gmail.com"
}
],
"engines": {
"node": ">=4.0.0"
},
"repository": "googleapis/nodejs-translate",
"main": "./src/index.js",

@@ -37,5 +16,4 @@ "files": [

"CONTRIBUTORS",
"COPYING"
"LICENSE"
],
"repository": "googlecloudplatform/google-cloud-node",
"keywords": [

@@ -53,6 +31,33 @@ "google apis client",

],
"contributors": [
"Ace Nassri <anassri@google.com>",
"Dave Gramlich <callmehiphop@gmail.com>",
"Eric Uldall <ericuldall@gmail.com>",
"Ernest Landrito <landrito@google.com>",
"Jason Dobry <jason.dobry@gmail.com>",
"Jason Dobry <jmdobry@users.noreply.github.com>",
"Luke Sneeringer <luke@sneeringer.com>",
"Luke Sneeringer <lukesneeringer@google.com>",
"Stephen Sawchuk <sawchuk@gmail.com>",
"Stephen Sawchuk <stephenplusplus@users.noreply.github.com>",
"Tim Swast <swast@google.com>",
"florencep <florenceperot@google.com>",
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>"
],
"scripts": {
"cover": "nyc --reporter=lcov mocha --require intelli-espower-loader test/*.js && nyc report",
"docs": "repo-tools exec -- jsdoc -c .jsdoc.js",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "repo-tools lint --cmd eslint -- src/ samples/ system-test/ test/",
"prettier": "repo-tools exec -- prettier --write src/*.js src/*/*.js samples/*.js samples/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js",
"publish-module": "node ../../scripts/publish.js translate",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
"system-test": "repo-tools test run --cmd mocha -- system-test/*.js --no-timeouts",
"test-no-cover": "repo-tools test run --cmd mocha -- test/*.js --no-timeouts",
"test": "repo-tools test run --cmd npm -- run cover"
},
"dependencies": {
"@google-cloud/common": "^0.13.0",
"arrify": "^1.0.0",
"extend": "^3.0.0",
"extend": "^3.0.1",
"is": "^3.0.1",

@@ -63,14 +68,18 @@ "is-html": "^1.0.0",

"devDependencies": {
"mocha": "^3.0.1",
"@google-cloud/nodejs-repo-tools": "^2.0.11",
"async": "^2.5.0",
"codecov": "^3.0.0",
"eslint": "^4.9.0",
"eslint-config-prettier": "^2.6.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-prettier": "^2.3.1",
"ink-docstrap": "^1.3.0",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.5.5",
"mocha": "^4.0.1",
"nyc": "^11.2.1",
"power-assert": "^1.4.4",
"prettier": "^1.7.4",
"proxyquire": "^1.7.10"
},
"scripts": {
"publish-module": "node ../../scripts/publish.js translate",
"test": "mocha test/*.js",
"system-test": "mocha system-test/*.js --no-timeouts --bail"
},
"license": "Apache-2.0",
"engines": {
"node": ">=4.0.0"
}
}

@@ -1,130 +0,131 @@

# @google-cloud/translate ([GA][versioning])
> Cloud Translation API Client Library for Node.js
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
*Looking for more Google APIs than just Translation? You might want to check out [`google-cloud`][google-cloud].*
# Google Cloud Translation API: Node.js Client
- [API Documentation][gcloud-translate-docs]
- [Official Documentation][cloud-translate-docs]
[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
[![CircleCI](https://img.shields.io/circleci/project/github/googleapis/nodejs-translate.svg?style=flat)](https://circleci.com/gh/googleapis/nodejs-translate)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/googleapis/nodejs-translate?branch=master&svg=true)](https://ci.appveyor.com/project/googleapis/nodejs-translate)
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-translate/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-translate)
> Node.js idiomatic client for [Cloud Translation API][product-docs].
```sh
$ npm install --save @google-cloud/translate
```
```js
var translate = require('@google-cloud/translate')({
projectId: 'grape-spaceship-123',
keyFilename: '/path/to/keyfile.json'
});
The [Cloud Translation API](https://cloud.google.com/translate/docs), can dynamically translate text between thousands of language pairs. The Cloud Translation API lets websites and programs integrate with the translation service programmatically. The Cloud Translation API is part of the larger Cloud Machine Learning API family.
// Translate a string of text.
translate.translate('Hello', 'es', function(err, translation) {
if (!err) {
// translation = 'Hola'
}
});
* [Cloud Translation API Node.js Client API Reference][client-docs]
* [Cloud Translation API Documentation][product-docs]
// Detect a language from a string of text.
translate.detect('Hello', function(err, results) {
if (!err) {
// results = {
// language: 'en',
// confidence: 1,
// input: 'Hello'
// }
}
});
Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in [Client Libraries Explained][explained].
// Get a list of supported languages.
translate.getLanguages(function(err, languages) {
if (!err) {
// languages = [
// 'af',
// 'ar',
// 'az',
// ...
// ]
}
});
[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
// Promises are also supported by omitting callbacks.
translate.getLanguages().then(function(data) {
var languages = data[0];
});
**Table of contents:**
// It's also possible to integrate with third-party Promise libraries.
var translate = require('@google-cloud/translate')({
promise: require('bluebird')
});
```
* [Quickstart](#quickstart)
* [Before you begin](#before-you-begin)
* [Installing the client library](#installing-the-client-library)
* [Using the client library](#using-the-client-library)
* [Samples](#samples)
* [Versioning](#versioning)
* [Contributing](#contributing)
* [License](#license)
## Quickstart
## Authentication
### Before you begin
It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Cloud services.
1. Select or create a Cloud Platform project.
### On Google Cloud Platform
[Go to the projects page][projects]
If you are running this client on Google Cloud Platform, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access.
1. Enable billing for your project.
``` js
var translate = require('@google-cloud/translate')();
// ...you're good to go!
```
[Enable billing][billing]
### With a Google Developers Service Account
1. Enable the Google Cloud Translation API API.
If you are not running this client on Google Cloud Platform, you need a Google Developers service account. To create a service account:
[Enable the API][enable_api]
1. Visit the [Google Developers Console][dev-console].
2. Create a new project or click on an existing project.
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
* Google Cloud Translation API
4. Navigate to **APIs & auth** > **Credentials** and then:
* If you want to use a new service account key, click on **Create credentials** and select **Service account key**. After the account key is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests.
* If you want to generate a new service account key for an existing service account, click on **Generate new JSON key** and download the JSON key file.
* If you want to use an API key, click on **Create credentials** and select **API key**. After the API key is created, you will see a newly opened modal with the API key in a field named **Your API key** that the library uses to authenticate your requests.
* If you want to generate a new API key for an existing API key, click on an existing API key and click **Regenerate key**.
1. [Set up authentication with a service account][auth] so you can access the
API from your local workstation.
``` js
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=translate.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started
var translate = require('@google-cloud/translate')({
projectId: projectId,
### Installing the client library
// The path to your key file:
keyFilename: '/path/to/keyfile.json'
npm install --save @google-cloud/translate
// Or the contents of the key file:
credentials: require('./path/to/keyfile.json')
### Using the client library
// Your API key (if not using a service account JSON file):
key: '...'
```javascript
// Imports the Google Cloud client library
const Translate = require('@google-cloud/translate');
// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';
// Instantiates a client
const translate = new Translate({
projectId: projectId,
});
// ...you're good to go!
// The text to translate
const text = 'Hello, world!';
// The target language
const target = 'ru';
// Translates some text into Russian
translate
.translate(text, target)
.then(results => {
const translation = results[0];
console.log(`Text: ${text}`);
console.log(`Translation: ${translation}`);
})
.catch(err => {
console.error('ERROR:', err);
});
```
### With an API key
## Samples
It's also possible to authenticate with an API key. To create an API key:
Samples are in the [`samples/`](https://github.com/googleapis/nodejs-translate/blob/master/samples) directory. The samples' `README.md`
has instructions for running the samples.
1. Visit the [Google Developers Console][dev-console].
2. Create a new project or click on an existing project.
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
* Google Translate API
4. Navigate to **APIs & auth** > **Credentials** and then click on **Create new Client ID** and select **API key**. You should then be presented with a pop-up containing your newly created key.
| Sample | Source Code |
| --------------------------- | --------------------------------- |
| Translate | [source code](https://github.com/googleapis/nodejs-translate/blob/master/samples/translate.js) |
```js
var translate = require('@google-cloud/translate')({
key: 'API Key'
});
The [Cloud Translation API Node.js Client API Reference][client-docs] documentation
also contains samples.
// ...you're good to go!
```
## Versioning
This library follows [Semantic Versioning](http://semver.org/).
[versioning]: https://github.com/GoogleCloudPlatform/google-cloud-node#versioning
[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node/
[api-key-howto]: https://cloud.google.com/translate/v2/using_rest#auth
[gcloud-translate-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/translate
[cloud-translate-docs]: https://cloud.google.com/translate/docs
This library is considered to be **General Availability (GA)**. This means it
is stable; the code surface will not change in backwards-incompatible ways
unless absolutely necessary (e.g. because of critical security issues) or with
an extensive deprecation period. Issues and requests against **GA** libraries
are addressed with the highest priority.
More Information: [Google Cloud Platform Launch Stages][launch_stages]
[launch_stages]: https://cloud.google.com/terms/launch-stages
## Contributing
Contributions welcome! See the [Contributing Guide](.github/CONTRIBUTING.md).
## License
Apache Version 2.0
See [LICENSE](LICENSE)
[client-docs]: https://cloud.google.com/nodejs/docs/reference/translate/latest/
[product-docs]: https://cloud.google.com/translate/docs

@@ -17,6 +17,2 @@ /*!

/*!
* @module translate
*/
'use strict';

@@ -35,2 +31,29 @@

/**
* @typedef {object} ClientConfig
* @property {string} [projectId] The project ID from the Google Developer's
* Console, e.g. 'grape-spaceship-123'. We will also check the environment
* variable `GCLOUD_PROJECT` for your project ID. If your app is running in
* an environment which supports {@link https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application Application Default Credentials},
* your project ID will be detected automatically.
* @property {string} [key] An API key. You should prefer using a Service
* Account key file instead of an API key.
* @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key
* downloaded from the Google Developers Console. If you provide a path to a
* JSON file, the `projectId` option above is not necessary. NOTE: .pem and
* .p12 require you to specify the `email` option as well.
* @property {string} [email] Account email address. Required when using a .pem
* or .p12 keyFilename.
* @property {object} [credentials] Credentials object.
* @property {string} [credentials.client_email]
* @property {string} [credentials.private_key]
* @property {boolean} [autoRetry=true] Automatically retry requests if the
* response is related to rate limits or certain intermittent server errors.
* We will exponentially backoff subsequent requests by default.
* @property {number} [maxRetries=3] Maximum number of automatic retries
* attempted before returning the error.
* @property {Constructor} [promise] Custom promise module to use instead of
* native Promises.
*/
/**
* With [Google Translate](https://cloud.google.com/translate), you can

@@ -42,10 +65,8 @@ * dynamically translate text between thousands of language pairs.

*
* @constructor
* @alias module:translate
* @class
*
* @resource [Getting Started]{@link https://cloud.google.com/translate/v2/getting_started}
* @resource [Identifying your application to Google]{@link https://cloud.google.com/translate/v2/using_rest#auth}
* @see [Getting Started]{@link https://cloud.google.com/translate/v2/getting_started}
* @see [Identifying your application to Google]{@link https://cloud.google.com/translate/v2/using_rest#auth}
*
* @param {object} options - [Configuration object](#/docs).
* @param {string=} options.key - An API key.
* @param {ClientConfig} [options] Configuration options.
*

@@ -59,7 +80,13 @@ * @example

* //-
*
* @example <caption>include:samples/quickstart.js</caption>
* region_tag:translate_quickstart
* Full quickstart example:
*/
function Translate(options) {
options = options || {};
if (!(this instanceof Translate)) {
options = common.util.normalizeArguments(this, options, {
projectIdRequired: false
projectIdRequired: false,
});

@@ -72,4 +99,3 @@ return new Translate(options);

if (process.env.GOOGLE_CLOUD_TRANSLATE_ENDPOINT) {
baseUrl = process.env.GOOGLE_CLOUD_TRANSLATE_ENDPOINT
.replace(/\/+$/, '');
baseUrl = process.env.GOOGLE_CLOUD_TRANSLATE_ENDPOINT.replace(/\/+$/, '');
}

@@ -86,3 +112,3 @@

packageJson: require('../package.json'),
projectIdRequired: false
projectIdRequired: false,
};

@@ -96,20 +122,34 @@

/**
* @typedef {array} DetectResponse
* @property {object|object[]} 0 The detection results.
* @property {string} 0.language The language code matched from the input.
* @property {number} [0.confidence] A float 0 - 1. The higher the number, the
* higher the confidence in language detection. Note, this is not always
* returned from the API.
* @property {object} 1 The full API response.
*/
/**
* @callback DetectCallback
* @param {?Error} err Request error, if any.
* @param {object|object[]} results The detection results.
* @param {string} results.language The language code matched from the input.
* @param {number} [results.confidence] A float 0 - 1. The higher the number, the
* higher the confidence in language detection. Note, this is not always
* returned from the API.
* @param {object} apiResponse The full API response.
*/
/**
* Detect the language used in a string or multiple strings.
*
* @resource [Detect Language]{@link https://cloud.google.com/translate/v2/using_rest#detect-language}
* @see [Detect Language]{@link https://cloud.google.com/translate/v2/using_rest#detect-language}
*
* @param {string|string[]} input - The source string input.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {object|object[]} callback.results - If a single string input was
* given, a single result object is given. Otherwise, it is an array of
* result objects.
* @param {string} callback.results[].language - The language code matched from
* the input.
* @param {number=} callback.results[].confidence - A float 0 - 1. The higher
* the number, the higher the confidence in language detection. Note, this
* is not always returned from the API.
* @param {object} callback.apiResponse - Raw API response.
* @param {DetectCallback} [callback] Callback function.
* @returns {Promise<DetectResponse>}
*
* @example
* const Translate = require('@google-cloud/translate');
*
* const translate = new Translate();
*
* //-

@@ -159,105 +199,81 @@ * // Detect the language from a single string input.

* });
*
* @example <caption>include:samples/translate.js</caption>
* region_tag:translate_detect_language
* Here's a full example:
*/
Translate.prototype.detect = function(input, callback) {
var inputIsArray = Array.isArray(input);
input = arrify(input);
this.request({
method: 'POST',
uri: '/detect',
json: {
q: input
}
}, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}
this.request(
{
method: 'POST',
uri: '/detect',
json: {
q: input,
},
},
function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}
var results = resp.data.detections.map(function(detection, index) {
var result = extend({}, detection[0], {
input: input[index]
var results = resp.data.detections.map(function(detection, index) {
var result = extend({}, detection[0], {
input: input[index],
});
// Deprecated.
delete result.isReliable;
return result;
});
// Deprecated.
delete result.isReliable;
if (input.length === 1 && !inputIsArray) {
results = results[0];
}
return result;
});
if (input.length === 1) {
results = results[0];
callback(null, results, resp);
}
callback(null, results, resp);
});
);
};
/**
* @typedef {array} GetLanguagesResponse
* @property {object[]} 0 The languages supported by the API.
* @property {string} 0.code The [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1)
* language code.
* @property {string} 0.name The language name. This can be translated into your
* preferred language with the `target` option.
* @property {object} 1 The full API response.
*/
/**
* @callback GetLanguagesCallback
* @param {?Error} err Request error, if any.
* @param {object[]} results The languages supported by the API.
* @param {string} results.code The [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1)
* language code.
* @param {string} results.name The language name. This can be translated into your
* preferred language with the `target` option.
* @param {object} apiResponse The full API response.
*/
/**
* Get an array of all supported languages.
*
* @resource [Discovering Supported Languages]{@link https://cloud.google.com/translate/v2/discovering-supported-languages-with-rest}
* @see [Discovering Supported Languages]{@link https://cloud.google.com/translate/v2/discovering-supported-languages-with-rest}
*
* @param {string=} target - Get the language names in a language other than
* @param {string} [target] Get the language names in a language other than
* English.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {object[]} callback.languages - The languages supported by the API.
* @param {string} callback.languages[].code - The [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1)
* language code.
* @param {string} callback.languages[].name - The language name. This can be
* translated into your preferred language with the `target` option
* described above.
* @param {object} callback.apiResponse - Raw API response.
* @param {GetLanguagesCallback} [callback] Callback function.
* @returns {Promise<GetLanguagesResponse>}
*
* @example
* translate.getLanguages(function(err, languages) {
* if (!err) {
* // languages = [
* // {
* // code: 'af',
* // name: 'Afrikaans'
* // },
* // {
* // code: 'ar',
* // name: 'Arabic'
* // },
* // {
* // code: 'az',
* // name: 'Azerbaijani'
* // },
* // ...
* // ]
* }
* });
* @example <caption>include:samples/translate.js</caption>
* region_tag:translate_list_codes
* Gets the language names in English:
*
* //-
* // Get the language names in a language other than English.
* //-
* translate.getLanguages('es', function(err, languages) {
* if (!err) {
* // languages = [
* // {
* // code: 'af',
* // name: 'afrikáans'
* // },
* // {
* // code: 'ar',
* // name: 'árabe'
* // },
* // {
* // code: 'az',
* // name: 'azerí'
* // },
* // ...
* // ]
* }
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* translate.getLanguages().then(function(data) {
* var languages = data[0];
* var apiResponse = data[1];
* });
* @example <caption>include:samples/translate.js</caption>
* region_tag:translate_list_language_names
* Gets the language names in a langauge other than English:
*/

@@ -273,3 +289,3 @@ Translate.prototype.getLanguages = function(target, callback) {

useQuerystring: true,
qs: {}
qs: {},
};

@@ -290,3 +306,3 @@

code: language.language,
name: language.name
name: language.name,
};

@@ -300,5 +316,33 @@ });

/**
* Translate request options.
*
* @typedef {object} TranslateRequest
* @property {string} [format] Set the text's format as `html` or `text`.
* If not provided, we will try to auto-detect if the text given is HTML. If
* not, we set the format as `text`.
* @property {string} [from] The ISO 639-1 language code the source input
* is written in.
* @property {string} [model] Set the model type requested for this
* translation. Please refer to the upstream documentation for possible
* values.
* @property {string} to The ISO 639-1 language code to translate the
* input to.
*/
/**
* @typedef {array} TranslateResponse
* @property {object|object[]} 0 If a single string input was given, a single
* translation is given. Otherwise, it is an array of translations.
* @property {object} 1 The full API response.
*/
/**
* @callback TranslateCallback
* @param {?Error} err Request error, if any.
* @param {object|object[]} translations If a single string input was given, a
* single translation is given. Otherwise, it is an array of translations.
* @param {object} apiResponse The full API response.
*/
/**
* Translate a string or multiple strings into another language.
*
* @resource [Translate Text](https://cloud.google.com/translate/v2/using_rest#Translate)
* @see [Translate Text](https://cloud.google.com/translate/v2/using_rest#Translate)
*

@@ -308,23 +352,9 @@ * @throws {Error} If `options` is provided as an object without a `to`

*
* @param {string|string[]} input - The source string input.
* @param {string|object=} options - If a string, it is interpreted as the
* @param {string|string[]} input The source string input.
* @param {string|TranslateRequest} [options] If a string, it is interpreted as the
* target ISO 639-1 language code to translate the source input to. (e.g.
* `en` for English). If an object, you may also specify the source
* language.
* @param {string} options.format - Set the text's format as `html` or `text`.
* If not provided, we will try to auto-detect if the text given is HTML. If
* not, we set the format as `text`.
* @param {string} options.from - The ISO 639-1 language code the source input
* is written in.
* @param {string} options.model - Set the model type requested for this
* translation. Please refer to the upstream documentation for possible
* values.
* @param {string} options.to - The ISO 639-1 language code to translate the
* input to.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {object|object[]} callback.translations - If a single string input was
* given, a single translation is given. Otherwise, it is an array of
* translations.
* @param {object} callback.apiResponse - Raw API response.
* @param {TranslateCallback} [callback] Callback function.
* @returns {Promise<TranslateResponse>}
*

@@ -381,4 +411,13 @@ * @example

* });
*
* @example <caption>include:samples/translate.js</caption>
* region_tag:translate_translate_text
* Full translation example:
*
* @example <caption>include:samples/translate.js</caption>
* region_tag:translate_text_with_model
* Translation using the premium model:
*/
Translate.prototype.translate = function(input, options, callback) {
var inputIsArray = Array.isArray(input);
input = arrify(input);

@@ -388,3 +427,3 @@

q: input,
format: options.format || (isHtml(input[0]) ? 'html' : 'text')
format: options.format || (isHtml(input[0]) ? 'html' : 'text'),
};

@@ -412,20 +451,23 @@

this.request({
method: 'POST',
uri: '',
json: body
}, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}
this.request(
{
method: 'POST',
uri: '',
json: body,
},
function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}
var translations = resp.data.translations.map(prop('translatedText'));
var translations = resp.data.translations.map(prop('translatedText'));
if (body.q.length === 1) {
translations = translations[0];
if (body.q.length === 1 && !inputIsArray) {
translations = translations[0];
}
callback(err, translations, resp);
}
callback(err, translations, resp);
});
);
};

@@ -454,7 +496,7 @@

qs: {
key: this.key
key: this.key,
},
headers: {
'User-Agent': common.util.getUserAgentFromPackageJson(PKG)
}
'User-Agent': common.util.getUserAgentFromPackageJson(PKG),
},
});

@@ -472,2 +514,31 @@

/**
* The `@google-cloud/translate` package has a single default export, the
* {@link Translate} class.
*
* See {@link Storage} and {@link ClientConfig} for client methods and
* configuration options.
*
* @module {constructor} @google-cloud/translate
* @alias nodejs-translate
*
* @example <caption>Install the client library with <a href="https://www.npmjs.com/">npm</a>:</caption>
* npm install --save @google-cloud/translate
*
* @example <caption>Import the client library:</caption>
* const Translate = require('@google-cloud/translate');
*
* @example <caption>Create a client that uses <a href="https://goo.gl/64dyYX">Application Default Credentials (ADC)</a>:</caption>
* const client = new Translate();
*
* @example <caption>Create a client with <a href="https://goo.gl/RXp6VL">explicit credentials</a>:</caption>
* const client = new Translate({
* projectId: 'your-project-id',
* keyFilename: '/path/to/keyfile.json',
* });
*
* @example <caption>include:samples/quickstart.js</caption>
* region_tag:translate_quickstart
* Full quickstart example:
*/
module.exports = Translate;

Sorry, the diff of this file is not supported yet

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