Skip to content

Commit

Permalink
Update Translate samples, with some minor tweaks to Language samples. (
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Nov 21, 2016
1 parent 70bc03f commit 8fe9517
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 78 deletions.
33 changes: 15 additions & 18 deletions packages/google-cloud-translate/samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,29 @@ text between thousands of language pairs.

View the [documentation][translate_docs] or the [source code][translate_code].

__Usage:__ `node translate --help`
__Usage:__ `node translate.js --help`

```
Commands:
detect <input..> Detect the language of the provided text or texts
list [target] List available translation languages. To return language names in a language other than
English, specify a target language.
translate <toLang> <input..> Translate the provided text or texts to the target language, optionally specifying the
source language.
detect <input..> Detects the language of one or more strings.
list [target] Lists available translation languages. To return
language names in a language other thanEnglish,
specify a target language.
translate <toLang> <input..> Translates one or more strings into 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 detect "Hello world!" Detect the language of "Hello world!".
node translate detect -k your-api-key "Hello world!" Detect the language of "Hello world!" and "Goodbye",
"Goodbye" supplying the API key inline..
node translate list -k your-api-key List available translation languages with names in
English, supplying the API key inline..
node translate list es List available translation languages with names in
node translate.js detect "Hello world!" Detects the language of a string.
node translate.js detect "Hello world!" "Goodbye" Detects the languages of multiple strings.
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 translate ru "Good morning!" Translate "Good morning!" to Russian, auto-detecting the
source language.
node translate translate ru "Good morning!" -f en -k Translate "Good morning!" to Russian from English,
your-api-key supplying the API key inline.
node translate.js translate ru "Good morning!" Translates a string into Russian.
node translate.js translate ru "Good morning!" "Good night!" Translates multiple strings into Russian.
For more information, see https://cloud.google.com/translate/docs
```
Expand Down
8 changes: 2 additions & 6 deletions packages/google-cloud-translate/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
"license": "Apache Version 2.0",
"author": "Google Inc.",
"scripts": {
"test": "mocha -R spec --require intelli-espower-loader ../test/_setup.js test/*.test.js",
"system-test": "mocha -R spec --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
"test": "cd ..; npm run st -- translate/system-test/*.test.js"
},
"dependencies": {
"@google-cloud/translate": "^0.4.0",
"@google-cloud/translate": "^0.5.0",
"yargs": "^6.4.0"
},
"devDependencies": {
"mocha": "^3.1.2"
},
"engines": {
"node": ">=4.3.2"
}
Expand Down
20 changes: 9 additions & 11 deletions packages/google-cloud-translate/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,13 +33,11 @@ const text = 'Hello, world!';
const target = 'ru';

// Translates some text into Russian
translateClient.translate(text, target, (err, translation) => {
if (err) {
console.error(err);
return;
}
translateClient.translate(text, target)
.then((results) => {
const translation = results[0];

console.log(`Text: ${text}`);
console.log(`Translation: ${translation}`);
});
console.log(`Text: ${text}`);
console.log(`Translation: ${translation}`);
});
// [END translate_quickstart]
43 changes: 0 additions & 43 deletions packages/google-cloud-translate/samples/test/quickstart.test.js

This file was deleted.

0 comments on commit 8fe9517

Please sign in to comment.