Automatic translate I18n po files with Google Translate API
Inspired by https://gist.github.com/xen/3ce7d597f53515facaf1 This python script interacts with Google Translate API. Source and target language/po-file are required to translate things automatically (see: usage).
pip install -r requirements.txt
You need an API key, generated by a project on https://console.cloud.google.com/apis/credentials
i18njson-translate.py [options] <inputfile> <outputfile>
Options:
--lang TEXT From what language text should be translated. Use one of
Google Translate languages codes. Example: 'en'
--to TEXT Target language should be in result file
--apikey Use API with key
--ftype [json|po] Accept input file in json or po format
--help Show this message and exit.
Example:
i18njson-translate.py --lang en --to de --ftype po --apikey XXXXXXXXXX /tmp/de.po security-guide/source/locale/de.po
Google Translate API works well. But sometimes the translated sentences make no sense or the target po file is broken. A human should look at it again after translating. And the file format should be also checked:
msgfmt --check-format security-guide/source/locale/de.po