Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/haya14busa/gtrans

Command-line translator using Google Translate
https://github.com/haya14busa/gtrans

Last synced: 29 days ago
JSON representation

Command-line translator using Google Translate

Awesome Lists containing this project

README

        

## gtrans - Command-line translator using Google Translate

## Installation

```
$ go get github.com/haya14busa/gtrans
```

## Setup

### 1) Get Google Translation API key
- See: https://cloud.google.com/translate/v2/quickstart

### 2) Set Google Translation API key as an envitonment variable along with other options.

Setup example:

```
$ echo 'export GOOGLE_TRANSLATE_API_KEY=' >> ~/.gtrans.sh
$ echo 'export GOOGLE_TRANSLATE_LANG=ja' >> ~/.gtrans.sh
$ echo 'export GOOGLE_TRANSLATE_SECOND_LANG=en' >> ~/.gtrans.sh
```

#### Bash
```
$ echo '[ -f ~/.gtrans.sh ] && source ~/.gtrans.sh' >> ~/.bashrc
```
#### Zsh
```
$ echo '[ -f ~/.gtrans.sh ] && source ~/.gtrans.sh' >> ~/.zshrc
```

Be careful not to expose your API key! Please use it at your own risk.

## Usage

```
Usage: gtrans [flags] [input text]
gtrans translates input text specified by argument or STDIN using Google Translate.
Source language will be automatically detected.

export GOOGLE_TRANSLATE_API_KEY=

[optional]
export GOOGLE_TRANSLATE_LANG=
export GOOGLE_TRANSLATE_SECOND_LANG=

If you set both GOOGLE_TRANSLATE_LANG and GOOGLE_TRANSLATE_SECOND_LANG,
gtrans automatically switches target langage.

Example:
$ gtrans "Golang is awesome"
Golangは素晴らしいです
$ gtrans "Golangは素晴らしいです"
Golang is great
$ gtrans "Golangは素晴らしいです" | gtrans | gtrans | gtrans ...

Flags:
-to string
target language
```

## Related projects
- Vim plugin: https://github.com/haya14busa/vim-gtrans