Skip to content

Latest commit

 

History

History
 
 

translate

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Google Cloud Platform logo

Google Cloud Translation API Node.js Samples

Build

The Cloud Translation API, 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.

Table of Contents

Setup

  1. Read Prerequisites and How to run a sample first.

  2. Install dependencies:

    With npm:

    npm install
    

    With yarn:

    yarn install
    

Samples

Translate

View the documentation or the source code.

Usage: node translate.js --help

Commands:
  detect <text..>                                 Detects the language of one or more strings.
  list [target]                                   Lists available translation languages. To language names in a language
                                                  other than English, specify a target language.
  translate <toLang> <text..>                     Translates one or more strings into the target language.
  translate-with-model <toLang> <model> <text..>  Translates one or more strings into the target language using the
                                                  specified model.

Options:
  --help  Show help                                                                                            [boolean]

Examples:
  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.js translate ru "Good morning!"                Translates a string into Russian.
  node translate.js translate ru "Good morning!" "Good night!"  Translates multiple strings into Russian.
  node translate.js translate-with-model ru nmt "Good           Translates multiple strings into Russian using the
  morning!" "Good night!"                                       Premium model.

For more information, see https://cloud.google.com/translate/docs

Running the tests

  1. Set the GCLOUD_PROJECT and GOOGLE_APPLICATION_CREDENTIALS environment variables.

  2. Run the tests:

    With npm:

    npm test
    

    With yarn:

    yarn test