FluentBundle class

A localization bundle: a set of compiled messages and terms in one locale (or ordered locale fallback chain), plus the functions that expressions may call.

Construct a bundle with a locale (or FluentBundle.locales for a fallback chain), load resources via addResource, then format messages with formatMessage or formatPattern. Errors during resolution are collected on the optional errors list rather than thrown.

NUMBER and DATETIME are always available. A bare FluentBundle('en') renders them digit-correct but locale-blind; pass a backend: from package:fluent_intl or package:fluent_icu for CLDR-aware formatting and real plural rules.

Implementers
Available extensions

Constructors

FluentBundle(String locale, {FluentBackend backend = const FluentBackend(), Map<String, FluentFunction>? functions, bool useIsolating = true, String transform(String text)?})
Creates a bundle for a single locale.
FluentBundle.locales(List<String> locales, {FluentBackend backend = const FluentBackend(), Map<String, FluentFunction>? functions, bool useIsolating = true, String transform(String text)?})
Creates a bundle with a locales fallback chain, most specific first.

Properties

backend FluentBackend
The backend that formats numbers and dates and classifies plurals. Defaults to the spec-fallback FluentBackend.
final
functions Map<String, FluentFunction>
Functions callable from FTL expressions. Always contains NUMBER and DATETIME; user-supplied functions are merged over them (a user-provided NUMBER overrides the built-in).
final
hashCode int
The hash code for this object.
no setterinherited
locales List<String>
Locales for this bundle, in priority order. The first locale drives number / date formatting and plural-category lookup.
final
parseJunk List<Junk>
All Junk entries accumulated by every prior addResource call, in the order they were parsed.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
transform String Function(String text)?
Optional pre-display text transform applied to every literal TextElement in a resolved pattern. String literals ({ "X" }), variant keys, and $variable substitutions are NOT transformed — only author-written pattern text. Useful for pseudo-localization (uppercasing, accent-padding, length expansion) during QA.
final
useIsolating bool
Whether to wrap placeable output in Unicode bidi-isolation marks (FSI U+2068 / PDI U+2069) when the rendered value is a string. The safe default for production UIs is ON; turn off only for tests where the wrapping interferes with assertions.
final

Methods

addResource(String source, {bool allowOverrides = false}) LoadResult
Parse and load FTL source into this bundle.
formatMessage(String id, {String? attribute, Map<String, Object?> args = const {}, List<FluentError>? errors}) String
Format the message identified by id. If attribute is supplied, the matching attribute's pattern is formatted instead of the message's value.
formatMessageAsSpans(String id, {String? attribute, Map<String, Object?> args = const {}, List<FluentError>? errors}) List<FluentSpan>

Available on FluentBundle, provided by the FluentMarkupFormatting extension

Format the message identified by id and parse any inline HTML5- shaped markup in the result into a FluentSpan tree.
formatPattern(CompiledPattern pattern, {Map<String, Object?> args = const {}, List<FluentError>? errors}) String
Format an arbitrary pattern. Most callers go through formatMessage instead; this is the lower-level entry point used when you've already resolved a pattern via getMessage.
getMessage(String id) CompiledMessage?
Look up a compiled message, or null if not found. The result is an opaque handle: pass message.value (or message.attributes[name]) to formatPattern for pattern-level caching in hot loops.
hasMessage(String id) bool
True if this bundle has a message with the given id.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited