Skip to content

OzzyCzech/potrans

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
 
 
src
 
 
 
 
 
 
 
 

PO file translator

Potrans it's PHP command line tool for automatic translation of Gettext PO file with Google Translator or DeepL Translator.

Google Translator

bin/potrans google --help
Description:
  Translate PO file with Google Translator API

Usage:
  google [options] [--] <input> [<output>]

Arguments:
  input                          Input PO file path
  output                         Output PO, MO files directory [default: "~/Downloads"]

Options:
      --from=FROM                Source language (default: en) [default: "en"]
      --to=TO                    Target language (default: cs) [default: "cs"]
      --all                      Re-translate including translated sentences
      --wait=WAIT                Wait between translations in milliseconds [default: false]
      --credentials=CREDENTIALS  Path to Google Credentials file [default: "./credentials.json"]
      --project=PROJECT          Google Cloud Project ID [default: project_id from credentials.json]
      --location=LOCATION        Google Cloud Location [default: "global"]
      --cache|--no-cache         Load from cache or not
  -h, --help                     Display help for the given command. When no command is given display help for the list command
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi|--no-ansi           Force (or disable --no-ansi) ANSI output
  -n, --no-interaction           Do not ask any interactive question
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Example commands

Follow command will translate whole content of tests/example-cs_CZ.po from English (default) to Czech language (default):

bin/potrans google tests/example-cs_CZ.po ~/Downloads --credentials=your-credentials-file.json

You can also change source and target language with --form and --to parametters:

bin/potrans google tests/example-cs_CZ.po ~/Downloads --credentials=your-credentials-file.json --from=ru --to=en

Google Translate API Pricing

Google Translate API pricing is based on usage. Translation usage is calculated in millions of characters (M), where 1 M = 10^6 characters. For more information, see the Pricing FAQ.

Getting Google Translation Credentials

  1. Open Google Cloud Console website
  2. Create a new Project (or select existing one)
  3. Search for translate API and enable it then
  4. Go to IAM & Admin > Service Accounts and click to + Create service account
  5. Chose Service account name and Service account ID and click to Create and continue
  6. Grant this service account access to project and add follow roles Cloud Translation API Editor, AutoML Editor
  7. Create new Keys and download credentials JSON file

You can watch it here:

DeepL Translator

bin/potrans deepl --help
Description:
  Translate PO file with DeepL Translator API

Usage:
  deepl [options] [--] <input> [<output>]

Arguments:
  input                   Input PO file path
  output                  Output PO, MO files directory [default: "~/Downloads"]

Options:
      --from=FROM         Source language (default: en) [default: "en"]
      --to=TO             Target language (default: cs) [default: "cs"]
      --all               Re-translate including translated sentences
      --wait=WAIT         Wait between translations in milliseconds [default: false]
      --apikey=APIKEY     Deepl API Key
      --cache|--no-cache  Load from cache or not
  -h, --help              Display help for the given command. When no command is given display help for the list command
  -q, --quiet             Do not output any message
  -V, --version           Display this application version
      --ansi|--no-ansi    Force (or disable --no-ansi) ANSI output
  -n, --no-interaction    Do not ask any interactive question
  -v|vv|vvv, --verbose    Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Example commands

bin/potrans deepl tests/example-cs_CZ.po ~/Downloads --apikey=123456

DeepL Translator API pricing

DeepL translator API pricing is based on monthly subscription. There is max. 500,000 characters/month for free.

For more information visit https://www.deepl.com/pro-api

Getting Api Key

  1. Register free Account
  2. Visit Account summary
  3. Search for Authentication Key for DeepL API

Install

composer require --dev om/potrans

Potrans development

  1. Install composer curl -s http://getcomposer.org/installer | php
  2. Run composer install for install all dependencies
  3. Install PHP Curl extension (curl and json PHP extensions)

For more information about Composer visit: https://getcomposer.org

If you had "command not found: potrans" return, just run the command like this: php bin/potrans and will run without problems.

Links

About

Command line tool for translate Gettext with Google Translator API

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages