Skip to main content

yet another i18n

A lightweight and developer-friendly Python translation library designed for simplicity and flexibility.

Features

  • 🌐 json-based translation: easy-to-use translations powered by simple JSON files.
  • 🔄 fallback language support: automatically provides translations in a fallback language when a specific translation is unavailable.
  • 🧩 nested values and placeholders: fully supports nested structures and dynamic placeholders within translations.
  • 🎛️ flexible translation styles: offers both preconfigured translations and on-the-fly translation generation.
  • 🛠️ developer experience focused api: designed with developers in mind, drawing inspiration from other projects.
  • ⚡ lightweight and simple: under 150 lines of code with no dependencies beyond Python's standard library.

Usage

0. Installation

Install the package via pip:

pip install yet-another-i18n

1. Initialization

Create a Translator instance by specifying at least the fallback locale.

from yai18n import Translator

translator = Translator(
    fallback_locale="en",
)
  • fallback_locale (required): The locale to use if the requested key is not found in any other locale.
  • default_locale (optional): The primary locale used when none is explicitly provided.
  • locale_folder_path (optional): Directory containing your JSON locale files. (default: "locales")
  • debug (optional): If True, locale files are reloaded before each translation (useful for development).

2. Locale Files

Each locale file should be a JSON file named <locale>.json within the specified locale_folder_path. Example:

en.json:

{
  "greeting": {
    "hello": "Hello, {name}!"
  }
}

3. Translation

To translate a key, simply call the Translator instance:

message = translator("greeting.hello", locale="en", args={"name": "Alice"})
print(message)  # Outputs: "Hello, Alice!"
  • key: A string path (e.g., "section.subsection.key") to the translated text.
  • locale (optional): Override the default locale for this translation.
  • args (optional): A dictionary to format dynamic placeholders in the translated text.

4. Fallback Behavior

If a key does not exist in the requested locale, the translator automatically uses the fallback_locale. If the key is not found there either, a KeyError is raised.

5. Error Handling

  • ValueError: Raised if a requested locale or default locale is not found.
  • TypeError: Raised if arguments to methods are of incorrect types.
  • KeyError: Raised if a translation key cannot be found in both the given and fallback locales.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

2mal3
2mal3

💻 📖 📦
Luis Schuimer
Luis Schuimer

🐛 📓

This project follows the all-contributors specification. Contributions of any kind welcome!

Metadata

Release files for yet-another-i18n 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yet-another-i18n 0.2.0
File Size Uploaded Provenance Actions
yet_another_i18n-0.2.0.tar.gz 6.1 kB Without provenance Details for yet_another_i18n-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yet-another-i18n 0.2.0
File Interpreter ABI Platform Actions
yet_another_i18n-0.2.0-py3-none-any.whl Python 3 none any Details for yet_another_i18n-0.2.0-py3-none-any.whl

Total release size: 11.9 kB

Release files / yet_another_i18n-0.2.0.tar.gz

Download URL yet_another_i18n-0.2.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3f36fe5665c8e219de7825bf5662b65ed74ec5bfc8bc0799bcc00af7e8f12fbb
BLAKE2b-256 checksum
How to use checksums
8987f9337ceaf98f5181425f7e3a2bc4d3465a143deb63416152128dd6a72c6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / yet_another_i18n-0.2.0-py3-none-any.whl

Download URL yet_another_i18n-0.2.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3e86d66ffcb4084cf429ab3a6a560e9210d292765d68de20fdba1e991cb939b
BLAKE2b-256 checksum
How to use checksums
57e18cf7864c17236e27a409b920b1c4123031e330cb2a4f6d61e93ca2538f0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Security for yet-another-i18n 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page