Skip to main content

Simple TOML-based localization manager

Project description

py-toml10n

Simple TOML-based localization manager for Python.

PyPI version Tests Python versions License: MIT

Installation

pip install py-toml10n

Quick Start

  1. Create localization files
locales/
├── en.toml
└── ru.toml

locales/en.toml:

hello = "Hello"
world = "World"

locales/ru.toml:

hello = "Привет"
world = "Мир"
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_toml10n-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_toml10n-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file py_toml10n-0.1.0.tar.gz.

File metadata

  • Download URL: py_toml10n-0.1.0.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

Hashes for py_toml10n-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d7da9f371efad84b57c3334a9ec93cd48061daa21cbb7167b5e1b5fa042517f
MD5 f1e10d28a62c6aa6493311f264bfd796
BLAKE2b-256 39355e9514173231008ad3d9c48d30ca1debf61bab125596d4273ead0dcbf7d1

See more details on using hashes here.

File details

Details for the file py_toml10n-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_toml10n-0.1.0-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

Hashes for py_toml10n-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fee846749cf1fb0ff5e523763416772aea8b62dd2a821dfadc30c15ec9789633
MD5 c3c61b3151c1ad18548d3ae39d6d1553
BLAKE2b-256 3affb01dc108287208fc2541cb9d014a1fdf8a86ea82129d7e2f3d8b1d545d1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page