Skip to main content

A library and CLI for translating Python applications and libraries.

Project description

l10n

A library and CLI for translating Python applications and libraries.

Our main design principle is "Simple things should be simple, complex things should be possible". We streamline the workflow that fits 95% of the projects and allow to configure every small detail to make it possible to fit the remaining 5%. Think about l10n as a high-level and friendly library comparing to low-level and less friendly locale, gettext, and babel.

Features:

  • Simple. We stripped away all unnecessary steps and concepts. All that's left is what is actually relevant for Python.
  • Type-safe. All other tools match translation.
  • Explicit. No global state, no variable injection. You know exactly what gets translated and to what language.
  • Zero-dependency runtime. There are a few small dependencies for CLI but they get installed only on your dev environment. On the production goes only one small library, l10n itself.
  • Pure Python. You can use it with PyPy, Numba, and any other interpreter.
  • Zero configuration. The tool knows about the modern Python packaging and automatically discovers the project structure, name, version, and all other relevant metadata.
  • Well documented. We make sure that you can pick up the tool without any prior knowledge of the topic.
  • Compatible with other tools. We use *.po and *.mo files that are compatible with gettext toolchain and all other translation tools.
  • Self-sufficient, no other tools required.
  • Asyncio-compatible and race-condition-free.
  • Fast. All teanslations on the production are compiled into a small and fast binary format.
  • Small. We don't include any generated data into the library distribution. Just a little of Python code.
  • Lazy. Any data is loaded only when you need it.
  • Can be used in libraries. The compiled translations are automatically placed next to your Python code and discovered at runtime.
  • Versatile. Most of the libraries in the wild are focused on web applications. This library fits any Python project.

l10n in 30 seconds

Install l10n:

python3 -m pip install 'l10n[cli]'

And there are all the changes you need to do in your code to support translations for a string:

from l10n import Locales
locales = Locales()

def say_hello(lang='en'):
    loc = locales[lang]
    msg = loc.get('Hello, world!')
    print(msg)

Now, let's translate it to Ukrainian:

  1. Extract all strings from the code that need to be translated:

    python3 -m l10n extract --lang uk
    
  2. Translate all extracted strings using Google Translate:

    python3 -m l10n translate
    
  3. Compile all translations into the binary format:

    python3 -m l10n compile
    

That's all! Now, your code supports translations:

from example import say_hello
say_hello(lang='uk')
# Привіт Світ!

If you want to manually adjust the translation text, just edit the languages/en.po file and run compile again. You don't even need to restart your app!

Read more in the documentation: l10n.orsinium.dev.

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

l10n-0.1.3.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

l10n-0.1.3-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file l10n-0.1.3.tar.gz.

File metadata

  • Download URL: l10n-0.1.3.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for l10n-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fdda1e9520c082dec51a3da9d3b0c6c81e62bf3e3e0d640f39c17a37afdf7caf
MD5 86f8ce30bdf4babed6432b21ef6e7f79
BLAKE2b-256 28a8a08ac5ea3df10013f674378db1b366c07d6c1e73ee0ac8405be6eae76dbc

See more details on using hashes here.

File details

Details for the file l10n-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: l10n-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for l10n-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a47f23d6de16c4510e804c1a8843e2194d098954c119b276564ea278598e2adf
MD5 96bd19104f4650f6ee4dd81ceb063769
BLAKE2b-256 04f6a26c5cbf4d65e2fc3550d0ac0e305bf01fa44658f90c54c984d131e2db13

See more details on using hashes here.

Supported by

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