Skip to main content

A lightweight localization module for Python projects

Project description

i18n

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"))

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: toml_i18n-1.0.3.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for toml_i18n-1.0.3.tar.gz
Algorithm Hash digest
SHA256 24322716e27d831275da76cd1aa4ddbc18931dabce108def84775d468632c971
MD5 cbfd5bd5d34a978c3e323c570ac0f128
BLAKE2b-256 ac7b5efd5a68dc4a78277ffa4ac7ffb31735fdc4afda6dcc7ee81b9c81641cb6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toml_i18n-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for toml_i18n-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9e77246d657b51cfa62335f0838ef003c5eef8d7077c12450d4cc96bc41478ac
MD5 effe11833b1badc0865057ad42d21820
BLAKE2b-256 49b9795011db5d53689ba3548181b923a5f0d1e1cdb5c9d03e28679ab1d1c004

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