{"id":3498,"library":"fluent-syntax","title":"Fluent Syntax Parser","description":"Fluent.syntax is the Python implementation for parsing, analyzing, processing, and serializing Fluent Translation List (FTL) files. It provides tools for working with the Abstract Syntax Tree (AST) of Fluent messages. As part of the broader Project Fluent, it helps unleash the expressive power of natural language in localization. The library is currently at version 0.19.0 and receives updates as part of the `python-fluent` project, with releases tied to Fluent specification updates and Python ecosystem changes.","status":"active","version":"0.19.0","language":"en","source_language":"en","source_url":"https://github.com/projectfluent/python-fluent","tags":["fluent","localization","l10n","parser","ast","i18n"],"install":[{"cmd":"pip install fluent-syntax","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"FluentParser","correct":"from fluent.syntax.parser import FluentParser"},{"symbol":"FluentSerializer","correct":"from fluent.syntax.serializer import FluentSerializer"},{"note":"Provides access to AST nodes like Resource, Message, Term, etc.","symbol":"ast","correct":"from fluent.syntax import ast"},{"note":"The Visitor and Transformer classes were refactored into `fluent.syntax.visitor` from `fluent.syntax.ast` in version 0.18.0.","wrong":"from fluent.syntax.ast import Visitor","symbol":"Visitor","correct":"from fluent.syntax.visitor import Visitor"},{"note":"The Visitor and Transformer classes were refactored into `fluent.syntax.visitor` from `fluent.syntax.ast` in version 0.18.0.","wrong":"from fluent.syntax.ast import Transformer","symbol":"Transformer","correct":"from fluent.syntax.visitor import Transformer"}],"quickstart":{"code":"from fluent.syntax.parser import FluentParser\nfrom fluent.syntax.serializer import FluentSerializer\n\nftl_source = \"\"\"\n# Welcome message\nhello = Hello, { $username }!\n\n# Plural example\nnum-emails = { $num ->\n    [one] You have one email.\n   *[other] You have { $num } emails.\n}\n\"\"\"\n\nparser = FluentParser()\nresource = parser.parse(ftl_source)\n\nprint(\"--- Parsed AST ---\")\n# For a more readable AST, you might want to use a custom visitor or ast.dump\n# For simplicity, we'll just print the resource object's representation.\nprint(resource)\n\nserializer = FluentSerializer()\nserialized_ftl = serializer.serialize(resource)\n\nprint(\"\\n--- Serialized FTL ---\")\nprint(serialized_ftl)\n","lang":"python","description":"This quickstart demonstrates parsing a Fluent Translation List (FTL) string into an Abstract Syntax Tree (AST) using `FluentParser` and then serializing the AST back into an FTL string using `FluentSerializer`. This showcases the core functionality of reading and writing Fluent syntax programmatically."},"warnings":[{"fix":"Upgrade to Python 3.6 or newer, or pin `fluent-syntax` to `<0.19.0`.","message":"Version 0.19.0 dropped official support for Python 2.7 and 3.5. Users on these Python versions should remain on `fluent-syntax<0.19.0`.","severity":"breaking","affected_versions":"0.19.0+"},{"fix":"Update import paths for `Visitor` and `Transformer` to `from fluent.syntax.visitor import ...`. Replace usages of `BaseNode.traverse` with the `Visitor` or `Transformer` pattern as appropriate.","message":"In version 0.18.0, the deprecated `BaseNode.traverse` method was removed. Additionally, `Visitor` and `Transformer` classes were refactored and moved from `fluent.syntax.ast` to `fluent.syntax.visitor`.","severity":"breaking","affected_versions":"0.18.0+"},{"fix":"Upgrade to `fluent-syntax` 0.18.1 or newer. If on an older version, ensure multiline patterns starting with special characters are carefully constructed or manually formatted to avoid serialization issues.","message":"Prior to version 0.18.1, serializing multiline patterns (especially those starting with special Fluent syntax characters like `[`, `.`, `*`, or `{`) could lead to incorrect output or syntax errors if the pattern elements didn't explicitly force a new line. `FluentSerializer` now correctly handles these cases.","severity":"gotcha","affected_versions":"<0.18.1"},{"message":"While `fluent.syntax.visitor.Transformer` allows in-place modification of an AST, care must be taken. Arbitrary modifications can lead to an AST that, when serialized, does not produce valid Fluent content. Always validate the transformed AST if performing complex manipulations.","severity":"gotcha"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}