Skip to main content

PyPI version License

doti18n
Modern, type-safe i18n / l10n library for Python.
The alternative to standart i18n libraries with dot-notation, ICU Message Format, IDE autocompletion and powerful CLI.

Overview

doti18n allows you to replace string-based dictionary lookups with intuitive object navigation. Instead of i18n["en"]["messages"]["error"], just write i18n["en"].messages.error.

It focuses on Developer Experience (DX) by providing a CLI tool to generate .pyi stubs. This enables IDE autocompletion and allows static type checkers (mypy, pyright) to catch missing keys, typo and type mismatching at build time.

Key Features

  • Dot-Notation: Access nested keys via attributes (data.key) and lists via indices (items[0]).
  • Type Safety: Generate stubs to get full IDE support and catch typos instantly.
  • Advanced ICUMF: Full support for ICU Message Format including nested select, plural, and custom formatters.
  • Pluralization: Robust support powered by Babel.
  • Format Agnostic: Supports YAML, JSON, XML, TOML out of the box. You can also implement custom loaders for other formats.
  • Safety Modes:
    • Strict: Raises exceptions for missing keys (good for dev/test).
    • Non-strict: Returns a safe wrapper and logs warnings (good for production).
  • Fallback: Automatically falls back to the default locale if a key is missing.
  • Macros: Define reusable snippets for common patterns (e.g., reusable ICU snippets).
  • Powerful CLI: Generate stubs, and run lint for missing keys.

Installation

Requires Python 3.11+

pip install doti18n

If you use YAML files:

pip install doti18n[yaml]

Usage

1. Create a localization file (locales/en.yaml):

__macros__: # Define a section with macros
    gender: {gender, select, male {He} female {She} other {They}}

greeting: "Hello {}!"
farewell: "Goodbye {name}!"

# Using macros
user_action: "@gender uploaded a new photo."
user_status: "@gender is currently online."

items:
    - name: "Item 1"
    - name: "Item 2"

# Basic key-based pluralization
notifications:
    one: "You have {count} new notification."
    other: "You have {count} new notifications."

# Complex ICU Message Format (Nesting + Select + Plural)
loot_msg: |
  {hero} found {type, select,
      weapon {{count, plural, one {a legendary sword} other {# rusty swords}}}
      potion {{count, plural, one {a healing potion} other {# healing potions}}}
      other {{count} items}
  } in the chest.

2. Access it in Python:

from doti18n import LocaleData

# Initialize (loads and caches data)
i18n = LocaleData("locales")
en = i18n["en"]

# 1. Standard formatting (Python-style)
print(en.greeting("John"))              # Output: Hello John!
print(en.farewell(name="Alice"))        # Output: Goodbye Alice!

# 2. Raw strings and graceful handling
print(en.farewell)                      # Output: Goodbye {name}! (Raw string)
print(en.farewell())                    # Output: Goodbye ! (Missing var handled)

# 3. Using strings with macros
print(en.user_action(gender="male"))    # Output: He uploaded a new photo.
print(en.user_status(gender="female"))  # Output: She is currently online.

# 4. List access
print(en.items[0].name)                 # Output: Item 1

# 5. Basic Pluralization
print(en.notifications(1))              # Output: You have 1 new notification.
print(en.notifications(5))              # Output: You have 5 new notifications.

# 6. Advanced ICUMF Logic
# "weapon" branch -> "one" sub-branch
print(en.loot_msg(hero="Arthur", type="weapon", count=1))
# Output: Arthur found a legendary sword in the chest.

# "potion" branch -> "other" sub-branch
print(en.loot_msg(hero="Merlin", type="potion", count=5))
# Output: Merlin found 5 healing potions in the chest.

CLI

Stub Generation / Type Safety

doti18n comes with a CLI to generate type stubs (.pyi).

Why use it?

  1. Autocompletion: Your IDE will suggest available keys as you type.
  2. Validation: Static analysis tools will flag errors if you try to access a key that doesn't exist.
  3. Deep ICUMF Introspection: The generator parses complex ICUMF strings (like the loot_msg example above) and creates precise function signatures.
    • Example: For loot_msg, it generates: def loot_msg(self, *, hero: str, type: str, count: int) -> str.
    • Your IDE will tell you exactly which arguments are required, even for deeply nested logic.

Commands:

# Generate stubs for all files in 'locales/' (default lang: en)
python -m doti18n stub locales/

# Generate stubs with a specific default language
python -m doti18n stub locales/ -lang fr

# Clean up generated stubs
python -m doti18n stub --clean

Note: Run this inside your virtual environment to ensure stubs are generated for the installed package.

Lint

Scan your translation files for missing keys, type mismatches and structural issues across locales.

# Lint all locales against the default language (en)
doti18n lint locales/

# Lint against a specific source language
doti18n lint locales/ -lang fr

Project Status

Alpha Stage: The API is stable but may evolve before the 1.0.0 release. Feedback and feature requests are highly appreciated!

Documentation

Documentation is available at darkj3suss.github.io/doti18n.

License

MIT License. See LICENSE for details.

Contact

Metadata

Release files for doti18n 0.12.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 doti18n 0.12.0
File Size Uploaded Provenance Actions
doti18n-0.12.0.tar.gz 39.7 kB With provenance Details for doti18n-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for doti18n 0.12.0
File Interpreter ABI Platform Actions
doti18n-0.12.0-py3-none-any.whl Python 3 none any Details for doti18n-0.12.0-py3-none-any.whl

Total release size: 94.7 kB

Release files / doti18n-0.12.0.tar.gz

Download URL doti18n-0.12.0.tar.gz
Size 39.7 kB
Tags Source
SHA-256 checksum
How to use checksums
70e8b8e780c8b2c540f31b6df2453f52d53a6b0e0fb4b99e213537148aa2552c
BLAKE2b-256 checksum
How to use checksums
9d03e06aa0bcc71a94430db1bf021aeaffa6157e45bf440e7ff4a32cf887f848
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Release files / doti18n-0.12.0-py3-none-any.whl

Download URL doti18n-0.12.0-py3-none-any.whl
Size 54.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce6888046575a52e2d861de93e7f469f597c9d41df6d31ea3dfd37bc2417a065
BLAKE2b-256 checksum
How to use checksums
336e1a29ff3daf70fb5bd82d613a22d17dfabbd3128d4fceaf817a1a42e6c4eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Security for doti18n 0.12.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for doti18n-0.12.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

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.

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