The @google-cloud/translate
package has the following named exports:
TranslationServiceClient
class - constructor for v3 of the Translation API. See v3.TranslationServiceClient for client methods.v3
- client for the v3 backend service version. It exports:TranslationServiceClient
- Reference to v3.TranslationServiceClient
v3beta1
- client for the v3beta1 backend service version. It exports:TranslationServiceClient
- Reference to v3beta1.TranslationServiceClient
v2
- client for the v2 backend service version. It exports:Translate
- Reference to v2.Translate
Examples
Install the v3 client library with npm:
npm install --save @google-cloud/translate
Import the v3 client library:
const {TranslationServiceClient} = require('@google-cloud/translate');
Create a v3 client that uses Application Default Credentials (ADC):
const client = new TranslationServiceClient();
Full quickstart example:
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// Imports the Google Cloud client library
const {Translate} = require('@google-cloud/translate').v2;
// Instantiates a client
const translate = new Translate({projectId});
async function quickStart() {
// The text to translate
const text = 'Hello, world!';
// The target language
const target = 'ru';
// Translates some text into Russian
const [translation] = await translate.translate(text, target);
console.log(`Text: ${text}`);
console.log(`Translation: ${translation}`);
}
quickStart();
Install the v3beta1 client library:
npm install --save @google-cloud/translate
Import the v3beta1 client library:
const {TranslationServiceClient} =
require('@google-cloud/translate').v3beta1;