tilsit-i18n
tilsit-i18n is a lightweight wrapper around Python’s built‑in gettext module.
Its purpose is to make internationalization simple and runtime‑switchable
with a single global translation object.
from pathlib import Path
from tilsit_i18n import tr
tr.localedir = Path(__file__).parent / "locale"
tr.language = "pl"
print(tr("Hello"))
✨ Features
- Simple, minimalistic interface: use
tr("message")anywhere - Runtime language switching (
tr.language = "pl") - Built on
gettext— full.po/.mocompatibility - Safe fallbacks:
- English (
"en") as default NullTranslationswhen.monot found
- English (
- Automatic logging of missing translation files
- Zero dependencies beyond Python +
loguru
📦 Installation
pip install tilsit-i18n
🧩 Usage
Initialize the translation directory
from pathlib import Path
from tilsit_i18n import tr
tr.localedir = Path(__file__).parent / "locale"
Set language
tr.language = "pl"
Translate messages
print(tr("Hello world"))
When the language is "en" (default), the message is returned unchanged.
🔧 Generating .mo files
Translations are edited in .po files and compiled to .mo.
Compile:
msgfmt.py -o messages.mo messages
🧪 Example .po
msgid "Hello"
msgstr "Cześć"
msgid "Exit"
msgstr "Wyjście"
⚠️ Error handling
tilsit-i18n logs common issues:
- Missing
localedir - Missing
.mofile for selected language
Example log:
ERROR localedir is not initialized
ERROR .mo file is not found
💡 Internals (how it works)
The core object:
@dataclass
class Translation:
default_language = "en"
default_domain = "messages"
localedir: Path | None = None
_language: str = "en"
_gnutranslations = gettext.NullTranslations()
It:
- Tracks language
- Loads the correct
GNUTranslationsobject - Falls back to English when needed
- Is callable:
tr("message")
🤝 Contributing
Issues, pull requests and suggestions are welcome!
📝 License
MIT License — see LICENSE for details.
Metadata
Release files for tilsit-i18n 1.0.0
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 | Actions |
|---|---|---|---|---|
| tilsit_i18n-1.0.0.tar.gz | 2.1 kB | Without provenance | Details for tilsit_i18n-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tilsit_i18n-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for tilsit_i18n-1.0.0-py3-none-any.whl |
Total release size: 5.1 kB
Release files / tilsit_i18n-1.0.0.tar.gz
| Download URL | tilsit_i18n-1.0.0.tar.gz |
|---|---|
| Size | 2.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75014336a73bd5f9d03eb1ad8cd9b54a54ebc1af39f14cac9140e98ccdc0fa7d
|
|
BLAKE2b-256 checksum How to use checksums |
e47a1be1c170bdbff19f4c25e37e43d052a8e297dd9b24b0b876f166d8561e44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.2
|
Release files / tilsit_i18n-1.0.0-py3-none-any.whl
| Download URL | tilsit_i18n-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9c888baaeba3e6c84e71cc4c299ec5caa96c797908def5b309a4b71aed2d1b02
|
|
BLAKE2b-256 checksum How to use checksums |
47d3d8d56b26ae1b9900bc25364ddf1ceeaf63609bb86ef65abbfcc2cc5300dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.2
|
Security for tilsit-i18n 1.0.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.