import { FluentBundle } from "https://deno.land/x/fluent@0.0.1/bundle/mod.ts";
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.
Examples
Example 1
Example 1
let errors = [];
bundle.addResource(
new FluentResource("hello = Hello, {$name}!"));
let hello = bundle.getMessage("hello");
if (hello.value) {
bundle.formatPattern(hello.value, {name: "Jane"}, errors);
// Returns "Hello, Jane!" and `errors` is empty.
bundle.formatPattern(hello.value, undefined, errors);
// Returns "Hello, {$name}!" and `errors` is now:
// [<ReferenceError: Unknown variable: name>]
}
Parameters
optional
args: Record<string, FluentVariable> | null = [UNSUPPORTED]