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

Uploaded Python 3

File details

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

File metadata

  • Download URL: toml_i18n-1.0.5.tar.gz
  • Upload date:
  • Size: 4.4 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.5.tar.gz
Algorithm Hash digest
SHA256 8d39dc7c338c49e774b2397dcf42b77c3e03ef62e3984cb08255fe29779275a9
MD5 5cfe0bdd5e272219b1112be8b6cec9c9
BLAKE2b-256 df6d01b2e4df9eb7aeac58ad0b91376a4a63e29c40640d213adeb614b5a48924

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toml_i18n-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cf93af33a1b53e09e3305b001b53dae6c260c27392f0e654a7e1df6fe023df73
MD5 3257d86cb8f18c0f6959a0f0b69c6d42
BLAKE2b-256 fe3c9dfa1738e6d7a7763e91dfa7c65810057d9adf115864c3e66c06389ba075

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