Skip to main content

This is a simple python library/CLI tool to translate .po files using various APIs.

Project description

poTranslation

Description

This is a simple python library/CLI tool to translate .po files using various APIs.

Installation

Install and update using pip:

pip install -U poTranslation

Usage

Create a .env file in your working directory or parent directory with the following content for the API you want to use:

TRANSLATOR_SERVICE=YOUR_TRANSLATOR_SERVICE
MS_API_KEY=YOUR_MS_API_KEY
MS_API_REGION=YOUR_MS_API_REGION
OPENAI_API_KEY=YOUR_OPENAI_API_KEY

CLI Examples

Translate a .po file

potranslate ./messages.po                       # translate untranslated text from 'en' to language specified in the .po file, save to ./messages.po
potranslate ./messages.po -s en -l zh           # translate from 'en' to 'zh'
potranslate ./messages.po -o ./translated.po    # translated .po file, save to ./translated.po
potranslate ./messages.po -F                    # force translation of all entries
potranslate ./messages.po -w                    # translate and NOT write to the file

Translate a directory of .po files

This would work with the .po files compiled using pybabel compile [options][Babel CLI]

potranslate -d app/translations                 # translate app/translations/<locale>/LC_MESSAGES/<domain>.po
potranslate -d app/translations -l zh           # translate app/translations/zh/LC_MESSAGES/<domain>.po
potranslate -d app/translations -D messages     # translate app/translations/<locale>/LC_MESSAGES/messages.po

CLI Usage

Usage: potranslate [OPTIONS] [PO_FILE_PATH]
Options:
  -s, --source_language TEXT  Translate from (language).  [default: en]
  -l, --locale TEXT           Translate to (language).  [default: (load from .po file)]
  -L, --lang TEXT             Programming langrage of formatted string.  [default: python]
  -o, --output PATH           Path to the output file.  [default: {po_file_path}]
  -e, --env PATH              Path to the env file.  [default: (load from cwd and parent dir)]
  -d, --directory PATH        Directory of the PO files.
  -D, --domain TEXT           Domain of the PO file.
  -F, --force                 Force translation of all entries.
  -v, --verbose               Enable verbose output.
  -q, --quiet                 Suppress output.
  -w, --write                 Write to the file.  [default: True]
  -h, --help                  Show this message and exit.

Features

Challenge: Some services require an glossary to be created before translation for formatted strings with placeholders.

License

Distributed under the BSD 3-Clause License. See LICENSE for more information.

Links

Source Code: https://github.com/StevenGuo42/poTranslation
Issue Tracker: https://github.com/StevenGuo42/poTranslation/issues
PyPI: https://pypi.org/project/poTranslation/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poTranslation-0.0.3a1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

poTranslation-0.0.3a1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file poTranslation-0.0.3a1.tar.gz.

File metadata

  • Download URL: poTranslation-0.0.3a1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for poTranslation-0.0.3a1.tar.gz
Algorithm Hash digest
SHA256 7b703d77f6564254ec4bf5bfa2eac8215b76e57716941d55ea6e2b424b0c9980
MD5 c7b9b83c58fd41a5a0e1274c67f5a3e5
BLAKE2b-256 9b0af2e7850381ecf2a5e7c344888c38c371f045bd2ed381fc0a7ae686f2fde9

See more details on using hashes here.

File details

Details for the file poTranslation-0.0.3a1-py3-none-any.whl.

File metadata

File hashes

Hashes for poTranslation-0.0.3a1-py3-none-any.whl
Algorithm Hash digest
SHA256 965911276dbba86228609d03572ae076472e51e026724a7bc31a70025f8ddccf
MD5 2350db01529340005b86dda657475517
BLAKE2b-256 395ff37b121fa95f3cd262994bb0172585e1d76af617b5f7b6f9d86443c87037

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page