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.4.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.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toml_i18n-1.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 c10cc008ecea00b6ddd22a156ea94a63ecabff402be2077a83a07a72d791a1f7
MD5 912181f04b3d5b323eea912f8ac70746
BLAKE2b-256 ebaebbc57dcb7666ba59948389b64721a7e3a9e82b8c1715d6b64511d6327749

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toml_i18n-1.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 288cee1006162f93a0a3f95db14c9d2c092f02e829d16440eb46fb0f46b73357
MD5 1f6f9520f6038b7905a1d6c2a57cad53
BLAKE2b-256 dc724ce908295e9c9d3246b2c787b104f39fa706d23700d3a7037a091d49742d

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