arnaudjuracek / google-translate-chain

Translate a string into another language, then another, then another, then...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

google-translate-chain

Translate a string into another language, then another, then another, then...


preview


Table of Contents


Installation

npm install --global arnaudjuracek/google-translate-chain

Usage

google-translate-chain takes a string and passes it through a chain of consecutive translations.

Note: the languages chain is designed so that its first item represent the language of the input string : if unknown, use the code 'AUTO', which will try to guess the correct language code.

CLI

google-translate-chain

Usage:
  gtc "Hello world" "EN, FR, JP, AR, EN"
  gtc "Hello world" -l "EN, FR, JP, AR, EN"
  gtc "Hello world" -l <file>
  gtc --help
  gtc --version
  gtc --supported-languages

Options:
  -h, --help                    Show this screen.
  -v, --version                 Print the current version.
  -l, --languages=<array|file>  A comma-separated list of langCode.

  --supported-languages         Print all supported languages.

Aliases:
  gtc, gt-chain, gtranslate-chain, google-translate-chain

Note: the external file used in gtc "Hello world" -l <file> must be a comma-separated list.


Programmatic

const googleTranslate = require('google-translate-chain')

const opts = {
  // This is the default onTranslate function
  onTranslate: function (input, output, from, to) {
    console.log(`[${to}] ${output}`)
  }
}

googleTranslate
  .chain('hello world', ['en, fr, en'], opts)
  .then(output => console.log('output'))
  .catch(err => console.log(err))
const googleTranslate = require('google-translate-chain')

console.log(googleTranslate.languages.isSupported('fr'))  // -> true
console.log(googleTranslate.languages.isSupported('foo')) // -> false
console.log(googleTranslate.languages.getCode('french'))  // -> fr
console.log(googleTranslate.languages.getCode('foo'))     // -> false

Credits

This module was created for the bot #confus_cius by Hakim Achbé, during the workshop "Machine Jacking" hosted by Chevalvert at Stereolux.


License

MIT.

About

Translate a string into another language, then another, then another, then...

License:MIT License


Languages

Language:JavaScript 100.0%