Skip to content

Instantly share code, notes, and snippets.

@c-bata
Last active October 31, 2018 01:33
Show Gist options
  • Save c-bata/27edee8a02815e1858ad94e77e78ed13 to your computer and use it in GitHub Desktop.
Save c-bata/27edee8a02815e1858ad94e77e78ed13 to your computer and use it in GitHub Desktop.
Translate po files using Google Translate API. This supports translation cache and calculating costs.
@c-bata
Copy link
Author

c-bata commented Oct 28, 2018

How to run

Setup

$ pip install --upgrade google-cloud-translate
$ export GOOGLE_SERVICE_ACCOUNT_JSON=/path/to/service-account-credential.json

Usage is like this:

$ python translate_po.py --help
usage: translate_po.py [-h] [--lang LANG] [--currency CURRENCY] filepath

positional arguments:
  filepath

optional arguments:
  -h, --help           show this help message and exit
  --lang LANG          target language (default: "ja")
  --currency CURRENCY  dollar per your currency. (default currency is yen:
                       111.90)
$ python translate_po.py ./po/index.po 1>./po/index_ja.po
Cost: 2.1417659999999996 yen

more details are: c-bata/webframework-in-python#13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment