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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for toml_i18n-1.0.7.tar.gz
Algorithm Hash digest
SHA256 1448a4a0e7cbcef4cc0c6791d3fe100cde365f34550420c864ed273631309005
MD5 64d28d30702f6212a0a0def680400940
BLAKE2b-256 104b4a0b76f62496f884fa2b7f55f0e92d35bccdefc7b5f4136e7215906a00ed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toml_i18n-1.0.7-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.13.5

File hashes

Hashes for toml_i18n-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 773f5af7f06e7d578914646d5b276e3f597ba3abe6199b927d0f32db6bd9c518
MD5 0987a7fc501e537ff46a0b36ac33752f
BLAKE2b-256 96788cba0d311a6567d16884fdb55333ec2861aef2d8a70a439dbdfef1d41e4d

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