{"id":4015,"library":"fluent-runtime","title":"Fluent Runtime","description":"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.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/projectfluent/python-fluent","tags":["localization","i18n","fluent","l10n"],"install":[{"cmd":"pip install fluent-runtime","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for parsing FTL resources; version `0.19.x` is required for `fluent-runtime 0.4.x` as per PyPI metadata.","package":"fluent.syntax","optional":false}],"imports":[{"symbol":"FluentResource","correct":"from fluent.runtime import FluentResource"},{"symbol":"FluentBundle","correct":"from fluent.runtime import FluentBundle"},{"symbol":"FluentLocalization","correct":"from fluent.runtime import FluentLocalization"}],"quickstart":{"code":"from fluent.runtime import FluentResource, FluentBundle, FluentLocalization\nfrom datetime import datetime\n\n# 1. Define your FTL resources\nresource_en = FluentResource(\"\"\"\nhello = Hello, { $name }!\nwelcome = Welcome, today is {DATETIME($date)}\n\"\"\")\n\nresource_fr = FluentResource(\"\"\"\nhello = Bonjour, { $name }!\nwelcome = Bienvenue, aujourd'hui c'est le {DATETIME($date)}\n\"\"\")\n\n# 2. Create FluentBundles for each locale\nbundle_en = FluentBundle([\"en-US\"], use_isolating=False)\nbundle_en.add_resource(resource_en)\n\nbundle_fr = FluentBundle([\"fr\"], use_isolating=False)\nbundle_fr.add_resource(resource_fr)\n\n# 3. Use FluentLocalization as the main entrypoint\nloc = FluentLocalization(\n    [\"en-US\", \"fr\"], \n    [\n        lambda locales: bundle_en, # Provider function for 'en-US'\n        lambda locales: bundle_fr  # Provider function for 'fr'\n    ]\n)\n\n# 4. Format messages\nmessage_en_hello, errors_en = loc.format_value(\"hello\", {\"name\": \"World\"})\nprint(f\"EN Hello: {message_en_hello}\")\n\nmessage_fr_welcome, errors_fr = loc.format_value(\"welcome\", {\"date\": datetime.now()})\nprint(f\"FR Welcome: {message_fr_welcome}\")\n\n# Example Output:\n# EN Hello: Hello, World!\n# FR Welcome: Bienvenue, aujourd'hui c'est le 2024-04-11 12:34:56","lang":"python","description":"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`."},"warnings":[{"fix":"Upgrade your Python environment to 3.6 or newer.","message":"Support 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`.","severity":"breaking","affected_versions":">=0.4.0"},{"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.","message":"Major 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.","severity":"breaking","affected_versions":">=0.3.0"},{"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`.","message":"`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.","severity":"gotcha","affected_versions":"*"},{"fix":"Migrate direct `FluentBundle` instantiation and usage to `FluentLocalization` for managing multiple bundles and locale resolution in complex applications.","message":"For applications requiring locale management, fallback mechanisms, or dynamic resource loading, `FluentLocalization` is the recommended high-level entry point over direct `FluentBundle` usage.","severity":"gotcha","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}