FluentBundle

Immutable runtime bundle for localizing messages.

A FluentBundle holds messages, terms, and functions for a specific locale, plus the configuration needed to format them. Construct one through FluentBundleBuilder (or the fluentBundle DSL) — the public constructor is internal so bundles are guaranteed immutable by construction.

Basic usage

val bundle = fluentBundle(locales = listOf(LanguageIdentifier.parse("en-US"))) {
resource("hello = Hello, { $name }!")
builtins()
}
val output = bundle.format("hello", fluentArgsOf("name" to "World"))

After build returns, every method on this class is safe to call from multiple threads simultaneously. The internal state is populated once and never mutated.

Properties

Link copied to clipboard

The list of locales this bundle supports (primary locale is first)

Link copied to clipboard

Whether Unicode bidi isolation marks are emitted

Functions

Link copied to clipboard

Snapshot copy of every message and term in this bundle, keyed by ID. Matches fluent-rs's FluentBundle::entries.

Link copied to clipboard
fun format(id: String, args: FluentArgs? = null): String?

Alias for formatMessage.

Link copied to clipboard
fun formatAttribute(id: String, attribute: String, args: FluentArgs? = null): String?

Format a specific attribute of a message by ID.

Link copied to clipboard
fun formatMessage(id: String, args: FluentArgs? = null): String?

Format a message by its ID, resolving all references.

Link copied to clipboard

Format a message and return both the result and any errors collected during resolution. Returns (null, [...]) for a missing message id and (null, []) for an empty-value message; otherwise (text, errors).

Link copied to clipboard
fun formatPattern(pattern: Pattern, args: FluentArgs? = null, errors: MutableList<FluentError> = mutableListOf(), rootMessageId: String? = null): String

Format a pattern directly.

Link copied to clipboard
fun getEntry(id: String): Entry?

Look up any entry (message or term) by ID. Corresponds to fluent-rs's FluentBundle::get_entry.

Link copied to clipboard

Look up a custom function by name.

Link copied to clipboard

Look up a message by its ID.

Link copied to clipboard

Look up a term by its ID.

Link copied to clipboard

The transform function passed at build time, or null if none.

Link copied to clipboard

Check if a custom function is registered.

Link copied to clipboard

Check if a message exists.

Link copied to clipboard

Check if a term exists. Accepts the term ID with or without the leading dash.

Link copied to clipboard

Get the memoizer for caching formatted values.