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.3.tar.gz (5.7 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.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_toml10n-0.1.3.tar.gz
  • Upload date:
  • Size: 5.7 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.3.tar.gz
Algorithm Hash digest
SHA256 789c6e51059c318e9626e29459cbdf8f40300f107c3ab2632e4774f4753cc4a9
MD5 be872527dc93eb7be8f39f08c108f057
BLAKE2b-256 1df525174d75e215846924d75097593cc154fb3d798cd453c17e2c979f4a8920

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_toml10n-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f0784cda57252d3ac6fed942c938d50ce4bcc5269c8bfa94f3a84fe7aa4646f2
MD5 7180a14191d7dfef761ef377615a821c
BLAKE2b-256 71eb4e2f95c887eae8d76908864bfb6570ed9cbc43725142f13b854947b4bbad

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