Translatable-Enums
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,
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!
with language('uk_UA'):
print(Messages.HELLO, Messages.WORLD) # Привіт, Світ!
print(Messages.HELLO, Messages.WORLD) # Bonjour le monde!
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"
# Messages.WORLD
msgid "World!"
msgstr ""
# Messages.HELLO
msgid "Hello,"
msgstr ""
Key-Format
python -m i18n main.py application.pot --key-format "{enum}.{name}.{value}"
Default: "{value}"
- enum - enum name
- name - attribute name
- value - attribute value
Examples:
{enum}.{name}.{value}
# Messages.WORLD
msgid "Messages.WORLD.World!"
msgstr ""
{enum}.{name}
# Messages.WORLD
msgid "Messages.WORLD"
msgstr ""
{value}
# Messages.WORLD
msgid "World!"
msgstr ""
Examples
See /examples for more examples.
Status
0.0.6 - RELEASED
Licence
Translatable-Enums is released under the MIT License. See the bundled LICENSE file for details.
Metadata
Release files for translatable-enums 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| translatable_enums-0.0.7.tar.gz | 7.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| translatable_enums-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.6 kB
Release files / translatable_enums-0.0.7.tar.gz
| Download URL | translatable_enums-0.0.7.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89dc6de14c54016a63c0c88db199801c9a8e3511c80c877ea099551b78ae71c0
|
|
BLAKE2b-256 checksum How to use checksums |
279935fbbfb00099ccf5cc8e79d5bff846dcef0263637dcf423053e06e248821
|
| 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.7-py3-none-any.whl
| Download URL | translatable_enums-0.0.7-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb158a99eebef01c2fc6210ec7a7001e3109edcb49881a8c0b9c690cf301d00e
|
|
BLAKE2b-256 checksum How to use checksums |
f597806aa57015dea725544984810c300996464ff063c34a0ab71871da07439f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.12.1 Windows/10
|
Security for translatable-enums 0.0.7
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.