Simple TOML-based localization manager
Project description
py-toml10n
Simple TOML-based localization manager for Python.
Installation
pip install py-toml10n
Quick Start
- Create localization files
locales/
├── en.toml
└── ru.toml
locales/en.toml:
hello = "Hello"
world = "World"
locales/ru.toml:
hello = "Привет"
world = "Мир"
- Use in your code
from toml10n import LocalizationManager
LM = LocalizationManager("locales/", default_language="en")
# Get a string in the default language
print(LM.get_string("hello")) # Hello
# Short syntax
print(LM["hello"]) # Hello
# Get a string in a specific language
print(LM.get_string("hello", language="ru")) # Привет
# List available languages
print(LM.supported_languages) # ['en', 'ru']
Features
-
Simple — just TOML files, nothing else.
-
Thread-safe — safe to use in multi-threaded applications.
-
Hot reload — call reload() to pick up changes without restarting.
-
Fallback — missing keys fall back to the default language.
-
Type hints — full type annotation support.
-
Zero dependencies — uses only stdlib tomllib (Python 3.11+).
API Reference
LocalizationManager(locale_dir="locales/", default_language="en")
Initialize the manager and load all .toml files from locale_dir.
locale_dir — path to the folder with .toml files
default_language — language code used when none is specified
get_string(key, language=None)
Return a localized string by key.
key — translation key
language — language code, uses default_language if None
Returns the string or [[key]] if not found
reload()
Reload all localization files. Useful for hot-reload during development.
load_file(filename)
Load a single .toml file by name. supported_languages
Property that returns a list of all loaded language codes.
Exceptions
LocaleDirNotFoundError — the directory doesn't exist
LanguageNotFoundError — requested language is not loaded
LocaleFileLoadError — a TOML file cannot be parsed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_toml10n-0.1.1.tar.gz.
File metadata
- Download URL: py_toml10n-0.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3a204e957810ac26ef09cf41efe0d1746222c45c5e1a12e175fe9799b266324
|
|
| MD5 |
e3af1fd89d3b055b2cd97de239e642ee
|
|
| BLAKE2b-256 |
1e9b0ca46e0156f015988c78140e8c8633b9bf255cb6eb07efb34c2cbe0e05f6
|
File details
Details for the file py_toml10n-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py_toml10n-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
976929896959d968ceb97800cc5665e7ff99457ed4ea4c0d2219fdf542ffc2d4
|
|
| MD5 |
33553128f2e6785df93ba570be6a44e2
|
|
| BLAKE2b-256 |
855ffa72d0605ba2532c387efc1b6845df777c821dd3e798ad608d248d02304f
|