Skip to main content

i18n_core: Internationalization Utilities

i18n_core is a lightweight, order-agnostic i18n layer on top of Babel. It lets apps and libraries register translations at any time, and all lookups react to locale changes without re-registration.

Features

  • Dynamic lookups: _, __, ngettext reflect the current locale.
  • Order-agnostic: libraries can register before or after the app; no merge-by-call-order.
  • Domain-aware: no cross-domain bleed; use per-domain catalogs with explicit precedence.
  • System locale detection and Windows LCID support.
  • WxPython helpers: i18n_core.gui.set_wx_locale.
  • Frozen env support (works with embedded data paths).

Installation

pip install i18n_core

Dependencies

  • Babel (>= 2.15, < 3.0)
  • platform_utils

Quickstart (App)

Use finalize_i18n once at startup to set the default domain and locale.

import os
from i18n_core import finalize_i18n, get_system_locale, _

locale_dir = os.path.join(os.path.dirname(__file__), "locale")
finalize_i18n(
    locale_id=get_system_locale(),
    app_domain="my_app",           # matches your .mo domain
    app_locale_path=locale_dir,     # <locale>/<LCID>/LC_MESSAGES/my_app.mo
)

print(_("Hello, world!"))

Change locale anytime — all lookups update automatically:

from i18n_core import set_locale

set_locale("de_DE")

Libraries

Two options — both are safe and idempotent:

  • Rely on inference (zero code): just from i18n_core import _ and call it. The top-level package name becomes your domain, and <pkg>/locale is used.

  • Explicit registration (recommended for clarity/perf):

import sys
import i18n_core

i18n_core.install_module_translation(
    domain="my_lib",                 # your .mo domain
    module=sys.modules[__name__],
    # locale_path=<path>              # optional; defaults to <pkg>/locale
)

print(_("A library string"))

WxPython Integration

import wx
import i18n_core.gui

app = wx.App()
wx_locale = i18n_core.gui.set_wx_locale(locale_path, locale_id)

APIs

  • finalize_i18n(locale_id=None, languages=None, app_domain=None, app_locale_path=None, install_into_builtins=True, priority=100) -> str
    • Configure default app domain/locale; install builtins wrappers.
  • install_module_translation(domain=None, locale_id=None, locale_path=None, module=None, priority=50) -> None
    • Register a provider for a domain and install wrappers into a specific module.
  • install_global_translation(domain, locale_id=None, locale_path=None) -> str
    • Back-compat shim: registers default domain and sets locale.
  • set_locale(locale_id: str) -> str
    • Normalize and apply process/Windows locale; updates i18n registry.
  • get_available_translations(domain, locale_path=None) -> Iterable[str]
    • List available locales for a domain across registered paths.
  • get_available_locales(domain, locale_path=None) -> Iterable[babel.core.Locale]
  • reset_locale() context manager: temporarily adjust process locale.

Precedence & Domains

  • Precedence is explicit: higher priority overrides lower within a domain (default: app=100, libraries=50). Ties resolve by first-registration order.
  • Lookups are domain-aware; module wrappers use their bound domain, and builtins use the default domain (or fall back to caller inference).

Backward Compatibility Notes

  • The legacy global-merge behavior is replaced by per-domain composites. active_translation now reflects the default domain, not a cross-domain merge.
  • install_global_translation and install_module_translation still exist but are now order-agnostic and idempotent.
  • Builtins _, __, ngettext are installed at import-time. If you previously used try: __; except NameError: install_global_translation(...), switch to finalize_i18n in the app entry point.

License

This project is licensed under the terms of the LICENSE file.

Metadata

Release files for i18n_core 2.0.1

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

Source distribution (sdist)

Source distribution for i18n_core 2.0.1
File Size Uploaded
i18n_core-2.0.1.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for i18n_core 2.0.1
File Interpreter ABI Platform
i18n_core-2.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 25.4 kB

Release files / i18n_core-2.0.1.tar.gz

Download URL i18n_core-2.0.1.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
705c3ee1708b127be18c893a7bc229176fc69183744c3df10d213d225e6818b2
BLAKE2b-256 checksum
How to use checksums
63721e393ae5dfc2bae4bc7f2e3b3ed9f855079b810ef1d6fc96fd952f4d02b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release files / i18n_core-2.0.1-py2.py3-none-any.whl

Download URL i18n_core-2.0.1-py2.py3-none-any.whl
Size 12.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3ccf4fe0c1b037be9b88780f8c4f7245e04760de695d4167989e1ed1efc2afac
BLAKE2b-256 checksum
How to use checksums
63b888887f55fbfbc1817c41d7d812a6fa1bf6c0fa89c369b1fd745b27448970
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.1

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.4.0

2 release files

0.38

2 release files

0.37

2 release files

0.36

2 release files

0.35

2 release files

0.34

2 release files

0.33

2 release files

0.3.9

2 release files

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