Skip to main content

A lightweight localization module for Python projects

Project description

toml_i18n

PyPI version License: MIT Python 3.7+

toml_i18n is a lightweight localization module for Python projects. It provides an easy way to manage and retrieve localized strings using TOML files.

Installation

pip install toml-i18n

Usage

Step 1: Create a Directory for Translations

In your project directory, create a subdirectory for your localization files (e.g., i18n).

Step 2: Add a Translation File

Inside the directory, create a TOML file for your localized strings, such as general.en.toml:

[general]

greeting = "Hello {name}!"

and

general.fr.toml:

[general]

greeting = "Bonjour {name}!"

Step 3: Initialize toml_i18n

Use the `TomlI18n class to set up the module with your desired locales and directory:

from toml_i18n import TomlI18n

TomlI18n.initialize(locale="fr", fallback_locale="en", directory="i18n")

This needs to be done only once when running the project.

Step 4: Retrieve Localized Strings

from toml_i18n import i18n

print(i18n("general.greeting", name="John Doe"))

Step 5: Format Numbers (Optional)

from toml_i18n import i18n_number

print(i18n_number(1234.56, decimals=2))  # Formats according to current locale

Key Features

  • Flexible Localization: Load translations from TOML files.
  • Fallback Locale: Automatically fall back to a default locale if a key is missing.
  • Dynamic Formatting: Use placeholders in your strings for flexible output.
  • Singleton Design: Easy setup and global access to translations.

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

toml_i18n-1.0.8.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

toml_i18n-1.0.8-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file toml_i18n-1.0.8.tar.gz.

File metadata

  • Download URL: toml_i18n-1.0.8.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for toml_i18n-1.0.8.tar.gz
Algorithm Hash digest
SHA256 39175e403d80f82c61cdf543f23ad50a5e6947e8f208662130a24c0a676cd13b
MD5 75cd865969aa1bda032d2a22b47a9fce
BLAKE2b-256 dc29f686bfb387dcd20a45a4db1d6f3529306e2bb1a4a61eccaa5b221aa61058

See more details on using hashes here.

File details

Details for the file toml_i18n-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: toml_i18n-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for toml_i18n-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 59b00c89a10e48faf72666a1d9d845ce91a9ada090f72d7e9fbad4d33fc1a58e
MD5 d4c3c77304e1107968dc4bfca8ac5547
BLAKE2b-256 a9d58ce5fe5f690f387e41bbfdd5af5037a7a3c9538ad29cdc837d1a83d40d0a

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