Skip to main content

pylanguage

Translation assistant for Python

Usage

Install

pip install --user pylanguage

Importing

from pylanguage.translator import Translator as T

Use in code

Suppose your project directory is of following structure:

myproject
 |
  ---- src/
 |   |
 |    --- __init__.py
 |    --- myfile.py    # Uses pylanguage
 |
  ---- translations
      |
       ---- base.json # base translations
      |
       ---- en_US.json # English US translations

Step 1: Import the library

from pylanguage.translator import Translator as T

Step 2: Create a translator object

Here, myfile.py uses the translations. So, under the import statement and before any strings, create the translations object. Here using en_US as an example,

import pathlib
from pylanguage.translator import Translator as T

proj_dir = str(pathlib.Path(__file__).parent.resolve())
translation_dir = str(pathlib.Path().joinpath(proj_dir, 'translations'))

p = T(base_file = 'base.json', lang_code = 'en_US', lang_dir = translation_dir)

Step 3: Use the get() method

Now, use the get() method of the Translator object.

Complete code of the previous example:

import pathlib
from pylanguage.translator import Translator as T

proj_dir = str(pathlib.Path(__file__).parent.resolve())
translation_dir = str(pathlib.Path().joinpath(proj_dir, 'translations'))

p = T(base_file = 'base.json', lang_code = 'en_US', lang_dir = translation_dir)

print(p.get("Hello World"))

The translations files

Both base file and language specific files use the following spec. Do note however that the base file will have same keys and values.

For the example above, both base.json and en_US.json will have the following content:

{
  "Hello World": "Hello World"
}

License

See LICENSE file.

Tl;dr: This project uses MIT License.

Complete docs

See Documentation

Metadata

Release files for pylanguage 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylanguage 0.1.0
File Size Uploaded Provenance Actions
pylanguage-0.1.0.tar.gz 39.3 kB Without provenance Details for pylanguage-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pylanguage 0.1.0
File Interpreter ABI Platform Actions
pylanguage-0.1.0-py3-none-any.whl Python 3 none any Details for pylanguage-0.1.0-py3-none-any.whl

Total release size: 43.1 kB

Release files / pylanguage-0.1.0.tar.gz

Download URL pylanguage-0.1.0.tar.gz
Size 39.3 kB
Tags Source
SHA-256 checksum
How to use checksums
30aea87362af969fac46a2d1f93526519238bc0194dd53a592b02384d11e69ce
BLAKE2b-256 checksum
How to use checksums
f9689c2775fcc3651d2158026821d3e3f3af7c0bd55bf07da8d91cfdf12e66fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.6

Release files / pylanguage-0.1.0-py3-none-any.whl

Download URL pylanguage-0.1.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec97e2cba932a5b4619f96d39606b5676d7a983850320e55faf6ebe7c31702cd
BLAKE2b-256 checksum
How to use checksums
481a3f575159c05c0cf98c28ce261d2846a14732b26cb23ba1d0070f5151fbc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.6

Security for pylanguage 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page