Babel

The Python internationalization library for locale-aware dates, numbers, and message catalogs

Library
PyPI
v2.18.0
1,463stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
83/100Excellent
Development Activity88
Maintenance68
Community88
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
73/100Good
Architecture76
Code Quality78
Innovation70
Learning Curve68

Babel is a Python library that provides an integrated collection of utilities for internationalizing and localizing applications, especially web-based ones. It wraps the CLDR (Common Locale Data Repository) to expose locale-aware formatting for dates, times, numbers, currencies, lists, and units, alongside a full toolchain for extracting, compiling, and working with gettext message catalogs. Originally developed for the Sphinx documentation project’s translation needs, Babel has become a foundational dependency across the Python web ecosystem, quietly powering the i18n layer of frameworks like Flask, Django extensions, and Jinja2-based sites.

What You Get

  • A Locale class exposing CLDR-derived display names, territories, scripts, and plural rules for any of the hundreds of locales CLDR tracks
  • Locale-aware date, time, and datetime formatting/parsing (babel.dates) including timezone-sensitive interval formatting
  • Locale-aware number, currency, and unit formatting/parsing (babel.numbers, babel.units) with correct grouping, decimal, and currency symbol conventions
  • A pybabel CLI and babel.messages API for extracting translatable strings from Python/Jinja2/JavaScript source, plus compiling and updating gettext .po/.mo catalog files
  • CLDR plural-rule evaluation (babel.plural) for correctly pluralizing translated strings across languages with complex plural categories
  • Support helpers (babel.support) for lazy translation proxies and format wrappers commonly used in web frameworks

Common Use Cases

  • Formatting dates, numbers, and currencies correctly for a user’s locale in a Flask, Django, or Pyramid web application
  • Extracting translatable strings from a Python + Jinja2 codebase into a .pot template and managing per-language .po translation files via the pybabel CLI
  • Building CLI tools or reports that need to render numbers, dates, and lists using conventions appropriate to the end user’s locale rather than hardcoded English formatting
  • Implementing correct plural forms in translated UI strings across languages with more than the English singular/plural distinction

Under The Hood

Architecture Babel is organized around two largely independent subsystems that share only the CLDR data layer. babel.core.Locale parses locale identifiers (e.g. en_US, zh_Hans_CN) and loads the matching CLDR dataset from the bundled babel/locale-data/*.dat files via babel.localedata; babel.dates, babel.numbers, babel.units, and babel.lists all take a Locale (or locale string) and format values against that dataset. The second subsystem, babel.messages, implements the gettext workflow: extract.py walks source trees with pluggable per-filetype extractors (Python, JavaScript, Jinja2), catalog.py models a translation catalog in memory, and pofile.py/mofile.py read and write the .po/.mo file formats; pybabel (via babel.messages.frontend) is the CLI entry point tying extraction, initialization, update, and compilation into distutils/setuptools-style commands. Tech Stack The library is pure Python with zero required runtime dependencies beyond the standard library (Python 3.8+ per pyproject.toml), keeping it easy to vendor into any web framework’s dependency tree; CLDR data is pre-compiled into binary .dat files at release time by scripts/import_cldr.py rather than parsed from XML at runtime, which keeps import and locale-lookup overhead low. Development tooling is Ruff for lint/format and pytest for the test suite, configured entirely in pyproject.toml. Code Quality The tests/ directory contains roughly 20 test modules and about 593 test functions/methods covering core locale parsing, date/number/unit formatting, plural rules, message extraction, and catalog I/O, including a dedicated test_smoke.py and a tests/messages/ subpackage for the gettext toolchain; conftest.py centralizes locale-parameterized fixtures used across the suite. Coverage is tracked via .coveragerc and CI runs through GitHub Actions. Code style favors explicit, well-documented functions over cleverness, with docstrings on public formatting functions showing example output. API Design The formatting functions follow a consistent format_x(value, locale=...) / parse_x(string, locale=...) pairing across dates, numbers, and units, so the mental model transfers directly between modules; Locale.parse() accepts flexible input (POSIX-style codes, CLDR identifiers) and normalizes them, lowering the barrier for developers unfamiliar with locale-tag conventions. The message-catalog side is more CLI-driven and requires learning pybabel’s command structure and a babel.cfg extraction mapping file, which is a steeper on-ramp than the formatting API but is well documented in the project’s Sphinx docs.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search