Registry / serialization / fluent-runtime

fluent-runtime

JSON →
library0.4.0pypypi✓ verified 24d ago

Fluent Runtime is the Python implementation of Project Fluent's runtime component, providing localization capabilities for expressive translations. It handles parsing and formatting of Fluent Localization (FTL) files. The current version is 0.4.0, with new releases occurring infrequently, often in conjunction with updates to the `fluent.syntax` library.

pip install fluent-runtime
INSTALL
IMPORT
SIG · FLUENT-RUNTIME
F
fluent-runtime
serializationpythonv0.4.0
Install
2.4s avg
Import
182ms
Disk
53MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.174s · 54.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.190s · 55MB
53MB installed
● package 53MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FluentResource
from fluent.runtime import FluentResource
FluentBundle
from fluent.runtime import FluentBundle
FluentLocalization
from fluent.runtime import FluentLocalization

Initializes `FluentResource` objects from FTL strings, then creates `FluentBundle` objects for specific locales. `FluentLocalization` acts as the high-level manager, providing an easy way to switch locales and format messages using `format_value`.

from fluent.runtime import FluentResource, FluentBundle, FluentLocalization from datetime import datetime # 1. Define your FTL resources resource_en = FluentResource(""" hello = Hello, { $name }! welcome = Welcome, today is {DATETIME($date)} """) resource_fr = FluentResource(""" hello = Bonjour, { $name }! welcome = Bienvenue, aujourd'hui c'est le {DATETIME($date)} """) # 2. Create FluentBundles for each locale bundle_en = FluentBundle(["en-US"], use_isolating=False) bundle_en.add_resource(resource_en) bundle_fr = FluentBundle(["fr"], use_isolating=False) bundle_fr.add_resource(resource_fr) # 3. Use FluentLocalization as the main entrypoint loc = FluentLocalization( ["en-US", "fr"], [ lambda locales: bundle_en, # Provider function for 'en-US' lambda locales: bundle_fr # Provider function for 'fr' ] ) # 4. Format messages message_en_hello, errors_en = loc.format_value("hello", {"name": "World"}) print(f"EN Hello: {message_en_hello}") message_fr_welcome, errors_fr = loc.format_value("welcome", {"date": datetime.now()}) print(f"FR Welcome: {message_fr_welcome}") # Example Output: # EN Hello: Hello, World! # FR Welcome: Bienvenue, aujourd'hui c'est le 2024-04-11 12:34:56
Debug
Known issues
breakingSupport for Python 2.7 and 3.5 was dropped in version 0.4.0. Users on older Python versions must remain on `fluent-runtime<0.4.0`.
fix
Upgrade your Python environment to 3.6 or newer.
affects: >=0.4.0
breakingMajor API changes were introduced in version 0.3.0. `FluentBundle.add_messages` was removed in favor of `FluentBundle.add_resource`. Additionally, `bundle.format()` was replaced by `bundle.format_pattern(bundle.get_message().value)` for direct formatting.
fix
Replace `bundle.add_messages(msgs)` with `bundle.add_resource(FluentResource(msgs))` and update direct `bundle.format()` calls with `bundle.format_pattern(bundle.get_message(message_id).value, args)` or use the higher-level `FluentLocalization.format_value` method.
affects: >=0.3.0
gotcha`fluent-runtime` is tightly coupled with `fluent.syntax`. Ensure your `fluent.syntax` version is compatible with your `fluent-runtime` version. For `fluent-runtime 0.4.x`, `fluent.syntax 0.19.x` is required.
fix
Installing `fluent-runtime` via pip will automatically pull in a compatible `fluent.syntax` version. If managing dependencies manually, ensure `fluent.syntax>=0.19,<0.20` is installed alongside `fluent-runtime 0.4.x`.
affects: *
gotchaFor applications requiring locale management, fallback mechanisms, or dynamic resource loading, `FluentLocalization` is the recommended high-level entry point over direct `FluentBundle` usage.
fix
Migrate direct `FluentBundle` instantiation and usage to `FluentLocalization` for managing multiple bundles and locale resolution in complex applications.
affects: >=0.3.0
Errors
Common errors & fixes
LookupError: Unknown message: 'your-message-id'
The requested message ID was not found in any of the loaded Fluent resources.
fix
Ensure that the FTL file contains a message with the exact ID 'your-message-id' and that the Fluent resources are loaded correctly by `FluentLocalization` or `FluentBundle`.
ModuleNotFoundError: No module named 'fluent.runtime'
The `fluent-runtime` library is not installed in the current Python environment, or the environment is not correctly activated.
fix
Install the library using pip: `pip install fluent-runtime`.
SyntaxError: Expected an identifier, got 'EOF'
There is a syntax error in one of your Fluent Translation List (FTL) files, preventing it from being parsed correctly by `fluent.syntax` (which `fluent-runtime` depends on).
fix
Review your FTL files for typos, missing characters (like closing braces), or incorrect Fluent syntax, especially around the indicated line or character position if available in the full traceback.
from fluent_runtime import FluentLocalization
The package name on PyPI is `fluent-runtime`, but the Python import path uses dots, so `fluent.runtime` is the correct module to import from.
fix
Change the import statement to `from fluent.runtime import FluentLocalization`.
Upgrade
Version history
0.4.0latest on PyPI · released Mar 16, 2023
Audit
Dependencies
fluent.syntaxrequiredRequired for parsing FTL resources; version `0.19.x` is required for `fluent-runtime 0.4.x` as per PyPI metadata.
Agent activity
9 hits · last 30 days
node
8
Resources
fluent-runtime — pip install fluent-runtime · libregistry