All Projects → skanehira → gtran

skanehira / gtran

Licence: MIT License
Google translate CLI

Programming Languages

go
31211 projects - #10 most used programming language

gtran

gtran is Google translate CLI tool it written in Go.
this using the translate api endpoint maked by Google Apps Script LanguageApp.
Also, this used in vim plugin translate.vim

About translate api endpoint

Translate logic.

function doPost(e) {
  var p = JSON.parse(e.postData.getDataAsString());
  if (p.text == "") {
    return ContentService.createTextOutput("text is empty");
  }
  if (p.source == "") {
    return ContentService.createTextOutput("source is empty");
  }
  if (p.target == "") {
    return ContentService.createTextOutput("target is empty");
  }
  
  var translatedText = LanguageApp.translate(p.text, p.source, p.target);
  return ContentService.createTextOutput(translatedText);
}

You can set env GTRAN_ENDPOINT or use the flag -endpoint to set yourself GAS endpoint.
Env takes precedence.

Requirement

  • Go 1.12 or higher

Install

$ git clone https://github.com/skanehira/gtran.git
$ cd gtran
$ go install

Usage

The language code is bellow.
https://cloud.google.com/translate/docs/languages

Usage of gtran:
  -endpoint string
        translate endpoint (default "https://script.google.com/macros/s/AKfycbywwDmlmQrNPYoxL90NCZYjoEzuzRcnRuUmFCPzEqG7VdWBAhU/exec")
  -source string
        translate source (default "en")
  -target string
        translate traget (default "ja")
  -text string
        translate source text

$ gtran -source=ja -target=en -text "海賊王におれはなる"
Become a Pirate King

$ gtran -text="Become a Pirate King"
海賊王になる
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].