Skip to main content

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.

Release files for translatable-enums 0.0.5

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

Source distribution (sdist)

Source distribution for translatable-enums 0.0.5
File Size Uploaded
translatable_enums-0.0.5.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for translatable-enums 0.0.5
File Interpreter ABI Platform
translatable_enums-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / translatable_enums-0.0.5.tar.gz

Download URL translatable_enums-0.0.5.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f57752f1fe3b444bd6f69612cadaaf179b62ce1c42d9aefd99a2603b536cbde8
BLAKE2b-256 checksum
How to use checksums
900ad0e06f5957af1dc4c6a38a08c1f61e6299c6ed909207f1450cb040b3804d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.1 Windows/10

Release files / translatable_enums-0.0.5-py3-none-any.whl

Download URL translatable_enums-0.0.5-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7471e67d61904fe3613fdf3eab76f9fe886198d74aa9bf416b26330650e7c813
BLAKE2b-256 checksum
How to use checksums
2c541b5891cc0f2b48f3eadcde80993fa711f5927284991ee19cc9d51a6a62f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.1 Windows/10

Release history Release notifications | RSS feed

0.0.7

2 release files

0.0.6

2 release files

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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