Skip to main content
   ┌──────────────────────────────────────────────────┐
   │  c o d e c h u — i 1 8 n                         │
   │   🌐  Hello   Merhaba   مرحبا   你好   שלום       │
   │  ····translate · negotiate · pluralize · RTL···· │
   └──────────────────────────────────────────────────┘

Internationalization helpers on top of stdlib gettext.

codechu-i18n

Locale negotiation (RFC 4647), CLDR-derived plural rules, RTL detection, ICU-style message formatting, and a lazy Translator that defers .mo loading until first use. Pure stdlib. Python 3.10+.

pip install codechu-i18n

What it gives you

  • Translator — lazy gettext wrapper with gettext, ngettext, pgettext, npgettext, and ICU-style format("Hello {name}!", name=…).
  • negotiate_locale(requested, available) — RFC 4647 lookup match.
  • detect_locale(env) — LC_ALL > LC_MESSAGES > LANG > LANGUAGE, caller passes the env dict (no implicit os.environ).
  • is_rtl(locale) — Arabic, Hebrew, Persian, Urdu, Pashto, …
  • plural_form(locale, n) — CLDR plural category index (handles Slavic three-form, Polish, Arabic six-form, Welsh, French zero-as-one, Asian no-plural).
  • lazy_gettext(msg) — module-level strings that resolve at render time, not import time.

Quick examples

Translator

from codechu_i18n import Translator

t = Translator("myapp", "locale", languages=["tr"], fallback="en")

t.gettext("Hello")                            # "Merhaba"
t.ngettext("{n} file", "{n} files", 3)        # "3 dosya"
t.pgettext("menu", "Open")                    # context-disambiguated
t.format("Hello {name}!", name="Ada")         # "Merhaba Ada!"

Locale negotiation

from codechu_i18n import negotiate_locale

available = ["tr-TR", "en-US", "de-DE"]
negotiate_locale(["fr", "tr"], available)        # "tr-TR"
negotiate_locale(["zh-Hant-HK"], ["zh-Hant"])    # "zh-Hant"
negotiate_locale(["xx"], available, fallback="en")  # "en"

Detect from env

import os
from codechu_i18n import detect_locale

detect_locale(dict(os.environ))   # "tr-TR" on a Turkish machine
detect_locale({})                 # ""  (no implicit ambient read)

RTL and plural rules

from codechu_i18n import is_rtl, plural_form

is_rtl("ar")          # True
is_rtl("tr-TR")       # False

plural_form("en", 1)  # 0 (one)
plural_form("en", 2)  # 1 (other)
plural_form("pl", 3)  # 1 (few)
plural_form("pl", 5)  # 2 (many)
plural_form("ar", 0)  # 0 (zero)
plural_form("tr", 5)  # 0 (Turkish has no plural distinction)

Lazy strings

from codechu_i18n import lazy_gettext as _

# Resolved every time str() is called — locale switches take effect.
GREETING = _("Hello")
print(str(GREETING))   # uses current installed translator

Library policy

This package is a thin layer over gettext. It does not ship .po/.mo catalogs — that is the consuming application's job. See the Codechu standards on library i18n for the rationale.

License

MIT — see LICENSE.

Part of Codechu.

Metadata

Release files for codechu-i18n 0.1.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 codechu-i18n 0.1.0
File Size Uploaded
codechu_i18n-0.1.0.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codechu-i18n 0.1.0
File Interpreter ABI Platform
codechu_i18n-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.3 kB

Release files / codechu_i18n-0.1.0.tar.gz

Download URL codechu_i18n-0.1.0.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d7d0ee05790be5826ce1e9944d8e5b3a5418dcf831eae89dd3fc59d80ae13aeb
BLAKE2b-256 checksum
How to use checksums
97838c5ff60f134b012e21d0055bea113505921d1027a9ff0386574b4bef6c6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 20, 2026.

Transparency log

Release files / codechu_i18n-0.1.0-py3-none-any.whl

Download URL codechu_i18n-0.1.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6baac23bdb964897cdf3b694f500167fc2bd9c2a8426a3919cf92eeb7c7b95a8
BLAKE2b-256 checksum
How to use checksums
2568a82d4208ed00fe87e6b41f94c61e0e9fc9af68b07c99582ee444d1dce931
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 May 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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