Skip to main content

Translatable-Enums is a i18n tool which uses built-in Enums as an convenient way to store translation keys.

Project description

Translatable-Enums

Lib logo

GitHub GitHub release (latest by date) PyPI - Downloads Coverage Code Style

Translatable-Enums is an i18n tool which uses built-in Enums as a convenient way to store translation keys.

Key-Features

  • No dependencies except the Python's standard library. Based on built-in enums & gettext
  • Powerful utility for extracting translation-keys
  • Easy-to-Use

Installation

You can use PIP:

pip install translatable-enums

Or Poetry:

poetry add translatable-enums

Getting-Started

from i18n import (
    TranslatableEnum,
    set_domain,
    set_language
)


class Messages(TranslatableEnum):
    HELLO = 'Hello,'
    WORLD = 'World!'


set_domain('app', './resources/languages')
set_language('en_US')

print(Messages.HELLO, Messages.WORLD)  # Hello, World!

set_language('uk_UA')

print(Messages.HELLO, Messages.WORLD)  # Привіт, Світ!

set_language('fr_FR')

print(Messages.HELLO, Messages.WORLD)  # Bonjour le monde!

print(Messages.HELLO.language('uk'), Messages.WORLD.language('en'))  # Привіт, World!

Extraction-Tools

To extract the translation-keys from application:

python -m i18n main.py application.pot

You will obtain a .pot file like this:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: \n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "Hello,"
msgstr ""

msgid "World!"
msgstr ""

Examples

See /examples for more examples.

Status

0.0.5 - RELEASED

Licence

Translatable-Enums is released under the MIT License. See the bundled LICENSE file for details.

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

translatable_enums-0.0.5.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

translatable_enums-0.0.5-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file translatable_enums-0.0.5.tar.gz.

File metadata

  • Download URL: translatable_enums-0.0.5.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Windows/10

File hashes

Hashes for translatable_enums-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f57752f1fe3b444bd6f69612cadaaf179b62ce1c42d9aefd99a2603b536cbde8
MD5 ac1b7caa0cd97fc2700ccfbf3d4c58cc
BLAKE2b-256 900ad0e06f5957af1dc4c6a38a08c1f61e6299c6ed909207f1450cb040b3804d

See more details on using hashes here.

File details

Details for the file translatable_enums-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for translatable_enums-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7471e67d61904fe3613fdf3eab76f9fe886198d74aa9bf416b26330650e7c813
MD5 1a97edee745f798197c5657c92ef9652
BLAKE2b-256 2c541b5891cc0f2b48f3eadcde80993fa711f5927284991ee19cc9d51a6a62f0

See more details on using hashes here.

Supported by

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