Skip to main content
Deno 2 is finally here 🎉️
Learn more
class FluentBundle
import { FluentBundle } from "https://deno.land/x/fluent@0.0.1/bundle/mod.ts";

Message bundles are single-language stores of translation resources. They are responsible for formatting message values and attributes to strings.

Constructors

new
FluentBundle(locales: string | Array<string>, unnamed 1?: { functions?: Record<string, FluentFunction>; useIsolating?: boolean; transform?: TextTransform; })

Create an instance of FluentBundle.

Properties

locales: Array<string>

Methods

addResource(res: FluentResource, unnamed 1?: { allowOverrides?: boolean; }): Array<Error>

Add a translation resource to the bundle.

formatPattern(
pattern: Pattern,
args?: Record<string, FluentVariable> | null,
errors?: Array<Error> | null,
): string

Format a Pattern to a string.

Format a raw Pattern into a string. args will be used to resolve references to variables passed as arguments to the translation.

In case of errors formatPattern will try to salvage as much of the translation as possible and will still return a string. For performance reasons, the encountered errors are not returned but instead are appended to the errors array passed as the third argument.

If errors is omitted, the first encountered error will be thrown.

getMessage(id: string): Message | undefined

Return a raw unformatted message object from the bundle.

Raw messages are {value, attributes} shapes containing translation units called Patterns. Patterns are implementation-specific; they should be treated as black boxes and formatted with FluentBundle.formatPattern.

hasMessage(id: string): boolean

Check if a message is present in the bundle.