Download the PHP package om/potrans without Composer
On this page you can find all versions of the php package om/potrans. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package potrans
Short Description Command line tool for translate Gettext with Google Translator API or Deepl API
License MIT
Informations about the package potrans
PO file translator
Potrans is a PHP command line tool for automatic translation of Gettext PO files with Google Translator or DeepL Translator.
Install
You can add om/potrans
to your PHP project as follows:
or you can clone this repository and then run ./bin/potrans
Google Translator
Example commands
Follow command will translate whole content of tests/example-cs_CZ.po
from English (default) to Czech language (
default):
You can also change source and target language with --form
and --to
parametters:
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
- Open Google Cloud Console website
- Create a new Project (or select existing one)
- Search for translate API and enable it then
- Go to IAM & Admin > Service Accounts and click to + Create service account
- Chose Service account name and Service account ID and click to Create and continue
- Grant this service account access to project and add follow roles Cloud Translation API Editor, AutoML Editor
- Create new Keys and download credentials JSON file
You can watch it here:
DeepL Translator
Example commands
DeepL Translator API pricing
DeepL Translator API pricing is based on a monthly subscription. There is a maximum of 500,000 characters/month for free.
For more information, visit DeepL Pro API.
Getting Api Key
- Register free Account
- Visit Account summary
- Find the Authentication Key for the DeepL API.
Environment variables
You can use environment variables to set the DeepL API key.
Custom translator
If you need to use a custom translator that behaves differently than the original translator, you have the option to use
the --translator
parameter as follows:
PHP file should contain implementation of Translator
interface and should return new instance:
You can find an example custom translator in the file DeepLTranslatorEscaped.php
Potrans development
- Install composer
curl -s http://getcomposer.org/installer | php
- Run
composer install
for install all dependencies - Install PHP Curl extension (curl and json PHP extensions)
For more information about Composer, visit: https://getcomposer.org
If you get "command not found: potrans"
, just run the command like this: php bin/potrans
and it will run without
problems.
Troubleshooting
cURL error: SSL certificate issue (Google Translate only)
You may encounter a problem caused by cURL like the following:
This is due to a missing issuer certificate cacert.pem
file, and curl won't verify SSL requests:
- Download http://curl.haxx.se/ca/cacert.pem
- Save is somewhere, e.g.
/usr/local/etc/cacert.pem
- Update your
php.ini
with the following:
You can verify it with phpinfo()
or php --info
. Read more
detailed instruction here.
Links
All versions of potrans with dependencies
gettext/gettext Version ^5.6
google/cloud-translate Version ^1.12
symfony/cache Version ^6.0
deeplcom/deepl-php Version ^1.2
vlucas/phpdotenv Version ^5.6