Skip to content

resoltico/FTLLexEngine

Repository files navigation

FTLLexEngine Art

PyPI Python Versions License: MIT

FTLLexEngine — Fluent localization runtime and parser for Python

FTLLexEngine is a Python library for the Fluent .ftl specification: format locale-aware prices, dates, and messages for 200+ locales, then parse localized user input back to exact Python types in the same stack.

Most setups handle the two directions separately — one library brews the outbound message, something hand-rolled to parse the reply back. Locale rules drift between them. FTLLexEngine runs both from the same locale, validates .ftl resources at boot before the first request, and keeps threads isolated without touching global state.

  • Format currency, dates, and plural messages correctly for 200+ locales via CLDR
  • Parse localized user input back to Decimal, date, or typed values — no float drift
  • Validate .ftl resources and message schemas at boot, before the first request
  • Thread-safe bundles, no global locale state

Copy-paste patterns · Workflow tour · PyPI

Both Ends of the Counter

A specialty coffee exporter invoices buyers in German. Buyers reply in their local number format. One runtime handles both ends:

from decimal import Decimal
from ftllexengine import FluentBundle
from ftllexengine.parsing import parse_currency

bundle = FluentBundle("de_DE", use_isolating=False)
bundle.add_resource('quote = Angebot: { CURRENCY($amount, currency: "EUR") }')

text, _ = bundle.format_pattern("quote", {"amount": Decimal("12450.00")})
# → "Angebot: 12.450,00 €" (non-breaking space before €)

parsed, _ = parse_currency("12.450,00 EUR", "de_DE", default_currency="EUR")
# → (Decimal("12450.00"), "EUR")

Same locale rules write the invoice and read the buyer's reply. No separate parser. No float approximation.

Where It Fits

Python apps using Fluent .ftl for messages, plural rules, and locale-aware formatting — especially when users send localized prices, dates, or quantities that need to come back as exact typed values. Systems that validate .ftl resources before accepting traffic, and concurrent apps that need locale isolation without shared mutable state.

Install

Full runtime — formatting, bidirectional parsing, CLDR locale data:

uv add ftllexengine[babel]
# or: pip install "ftllexengine[babel]"

Parser only — FTL syntax, AST, validation, zero Babel dependency:

uv add ftllexengine
# or: pip install ftllexengine

Python 3.13+. Fully typed. Built on the Fluent specification with CLDR data via Babel.

Maintainers: Release protocol.

Legal

MIT-licensed. The optional [babel] extra adds Babel under BSD-3-Clause. FTLLexEngine is an independent implementation of the Fluent syntax specification and is not affiliated with or endorsed by Mozilla.

LICENSE · NOTICE · PATENTS.md

About

Python runtime for the Fluent (FTL) specification: bidirectional parsing, CLDR-backed locale-aware formatting, and fail-fast boot validation with structured audit evidence.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors