Python library for loading YAML localizations with dot access and pluralization.
Project description
doti18n

Simple and intuitive Python library for loading localizations from YAML files and accessing them easily using dot notation, with powerful support for plural forms and nested data structures.
Description
doti18n provides a convenient way to manage your application's localization strings. By loading data from standard YAML files, the library allows you to access nested translations using a simple dot syntax (messages.status.online) for dictionary keys and index syntax (items[0]) for list elements. You can combine these for intuitive navigation through complex nested structures (pages[0].title).
Special attention is given to pluralization support using the Babel library, which is critical for correct localization across different languages. An automatic fallback mechanism to the default locale's value is also implemented if a key or path is missing in the requested locale.
The library offers both a forgiving non-strict mode (returning a special wrapper and logging warnings) and a strict mode (raising exceptions) for handling missing paths.
It's designed for ease of use and performance (data is loaded once during initialization and translator objects are cached).
Features
- Loading localization data from YAML files.
- Intuitive access to nested data structures (dictionaries and lists) using dot notation (
.) for dictionary keys and index notation ([]) for list elements. - Support for combined access paths (
data.list[0].nested_key). - Strict mode (
strict=True) to raise exceptions (AttributeError,IndexError,TypeError) on missing paths or incorrect usage. - Non-strict mode (default) to return a special
NoneWrapperobject and log a warning on missing paths. - Pluralization support for count-dependent strings (requires
Babel). - Automatic fallback to the default locale if a key/path is missing in the current locale.
- Caching of loaded data and translator objects for efficient access.
- Handles explicit
nullvalues in YAML, distinguishing them from missing paths.
Installation
doti18n is available on PyPI.
Install the basic version (without pluralization support):
pip install doti18n
For pluralization support (recommended), install with the optional pluralization dependency:
pip install doti18n[pluralization]
Note: Pluralization support is implemented using the Babel library. If you install doti18n without the [pluralization] optional dependency, pluralization functionality will be limited or unavailable, and the library will log a warning about the missing Babel dependency.
Project Status
This project is in an early stage of development (Alpha). The API may change in future versions before reaching a stable (1.0.0) release. Any feedback and suggestions are welcome!
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
If you have questions, feel free to open an issue on GitHub. Or you can message me on Telegram
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 Distributions
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 doti18n-0.1.0-py3-none-any.whl.
File metadata
- Download URL: doti18n-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e23e4e5b121b8e397841e88c84c3b552c37863c5603045b816cbf6129878681a
|
|
| MD5 |
423e900ee4fdcb3e050f36cd30cd51ce
|
|
| BLAKE2b-256 |
497cc98cb6bb1714ed02abf86a88b5bc2c0093ddefa122bae1e4a80faff8b478
|