diff --git a/translate/README.md b/translate/README.md index 73e6e022ea..f1763a09f5 100644 --- a/translate/README.md +++ b/translate/README.md @@ -39,19 +39,15 @@ Commands: translate Translates the provided text or texts to the target language. Options: - --apiKey, -k Your Translate API key. Defaults to the value of the TRANSLATE_API_KEY environment variable. [string] - --help Show help [boolean] + --help Show help [boolean] Examples: - node translate.js detect "Hello world!" Detects the language of "Hello world!". - node translate.js detect -k YOUR_API_KEY "Hello world!" Detects the language of "Hello world!" and "Goodbye", - "Goodbye" supplying the API key inline. - node translate.js list -k YOUR_API_KEY Lists available translation languages with names in - English, supplying the API key inline. - node translate.js list es Lists available translation languages with names in - Spanish. - node translate.js translate ru "Good morning!" Translates "Good morning!" to Russian, auto-detecting - the source language. + node translate.js detect "Hello world!" Detects the language of "Hello world!". + node translate.js detect "Hello world!" "Goodbye" Detects the language of "Hello world!" and "Goodbye". + node translate.js list Lists available translation languages with names in English. + node translate.js list es Lists available translation languages with names in Spanish. + node translate.js translate ru "Good morning!" Translates "Good morning!" to Russian, auto-detecting the source + language. For more information, see https://cloud.google.com/translate/docs ``` diff --git a/translate/quickstart.js b/translate/quickstart.js index 456099f7c1..7bb0715b24 100644 --- a/translate/quickstart.js +++ b/translate/quickstart.js @@ -19,12 +19,12 @@ // Imports the Google Cloud client library const Translate = require('@google-cloud/translate'); -// Your Translate API key -const apiKey = 'YOUR_API_KEY'; +// Your Google Cloud Platform project ID +const projectId = 'YOUR_PROJECT_ID'; // Instantiates a client const translateClient = Translate({ - key: apiKey + projectId: projectId }); // The text to translate diff --git a/translate/system-test/quickstart.test.js b/translate/system-test/quickstart.test.js index 853dc489a9..d41753da33 100644 --- a/translate/system-test/quickstart.test.js +++ b/translate/system-test/quickstart.test.js @@ -16,9 +16,7 @@ 'use strict'; const proxyquire = require(`proxyquire`).noPreserveCache(); -const translate = proxyquire(`@google-cloud/translate`, {})({ - key: process.env.TRANSLATE_API_KEY -}); +const translate = proxyquire(`@google-cloud/translate`, {})(); describe(`translate:quickstart`, () => { it(`should translate a string`, (done) => { diff --git a/translate/system-test/translate.test.js b/translate/system-test/translate.test.js index 942c08ae1b..092bc20098 100644 --- a/translate/system-test/translate.test.js +++ b/translate/system-test/translate.test.js @@ -25,13 +25,7 @@ const text = `Hello world!`; const toLang = `ru`; describe(`translate:translate`, () => { - const translate = Translate({ - key: process.env.TRANSLATE_API_KEY - }); - if (!process.env.TRANSLATE_API_KEY) { - process.stdout.write(`Skipping Translate API tests...\n`); - return; - } + const translate = Translate(); it(`should detect language`, () => { const output = run(`${cmd} detect "${text}"`, cwd); diff --git a/translate/translate.js b/translate/translate.js index f4487dbc3d..11b9872bfb 100644 --- a/translate/translate.js +++ b/translate/translate.js @@ -20,11 +20,7 @@ const Translate = require('@google-cloud/translate'); // [START translate_detect_language] function detectLanguage (input) { // Instantiates a client - const translate = Translate({ - // The Translate API uses an API key for authentication. This sample looks - // for the key in an environment variable. - key: process.env.TRANSLATE_API_KEY - }); + const translate = Translate(); // Detects the language. "input" can be a string for detecting the language of // a single piece of text, or an array of strings for detecting the languages @@ -41,11 +37,7 @@ function detectLanguage (input) { // [START translate_list_codes] function listLanguages () { // Instantiates a client - const translate = Translate({ - // The Translate API uses an API key for authentication. This sample looks - // for the key in an environment variable. - key: process.env.TRANSLATE_API_KEY - }); + const translate = Translate(); // Lists available translation language with their names in English (the default). return translate.getLanguages() @@ -62,11 +54,7 @@ function listLanguages () { // [START translate_list_language_names] function listLanguagesWithTarget (target) { // Instantiates a client - const translate = Translate({ - // The Translate API uses an API key for authentication. This sample looks - // for the key in an environment variable. - key: process.env.TRANSLATE_API_KEY - }); + const translate = Translate(); // Lists available translation language with their names in a target language return translate.getLanguages(target) @@ -83,11 +71,7 @@ function listLanguagesWithTarget (target) { // [START translate_translate_text] function translateText (input, target) { // Instantiates a client - const translate = Translate({ - // The Translate API uses an API key for authentication. This sample looks - // for the key in an environment variable. - key: process.env.TRANSLATE_API_KEY - }); + const translate = Translate(); // Translates the text into the target language. "input" can be a string for // translating a single piece of text, or an array of strings for translating @@ -105,15 +89,9 @@ function translateText (input, target) { require(`yargs`) .demand(1) .command(`detect `, `Detects the language of the provided text or texts`, {}, (opts) => { - if (!process.env.TRANSLATE_API_KEY) { - process.env.TRANSLATE_API_KEY = opts.apiKey; - } detectLanguage(opts.input); }) .command(`list [target]`, `Lists available translation languages. To return language names in a language other than English, specify a target language.`, {}, (opts) => { - if (!process.env.TRANSLATE_API_KEY) { - process.env.TRANSLATE_API_KEY = opts.apiKey; - } if (opts.target) { listLanguagesWithTarget(opts.target); } else { @@ -121,22 +99,11 @@ require(`yargs`) } }) .command(`translate `, `Translates the provided text or texts to the target language.`, {}, (opts) => { - if (!process.env.TRANSLATE_API_KEY) { - process.env.TRANSLATE_API_KEY = opts.apiKey; - } translateText(opts.input, opts.toLang); }) - .option(`apiKey`, { - alias: `k`, - global: true, - requiresArg: true, - default: process.env.TRANSLATE_API_KEY, - type: `string`, - description: `Your Translate API key. Defaults to the value of the TRANSLATE_API_KEY environment variable.` - }) .example(`node $0 detect "Hello world!"`, `Detects the language of "Hello world!".`) - .example(`node $0 detect -k YOUR_API_KEY "Hello world!" "Goodbye"`, `Detects the language of "Hello world!" and "Goodbye", supplying the API key inline.`) - .example(`node $0 list -k YOUR_API_KEY`, `Lists available translation languages with names in English, supplying the API key inline.`) + .example(`node $0 detect "Hello world!" "Goodbye"`, `Detects the language of "Hello world!" and "Goodbye".`) + .example(`node $0 list`, `Lists available translation languages with names in English.`) .example(`node $0 list es`, `Lists available translation languages with names in Spanish.`) .example(`node $0 translate ru "Good morning!"`, `Translates "Good morning!" to Russian, auto-detecting the source language.`) .wrap(120)