Cldr.Message.V2.Interpreter (Cldr Messages v2.0.0)

Copy Markdown View Source

Interprets a MessageFormat 2 AST and produces formatted output.

The AST is produced by Cldr.Message.V2.Parser and uses tuples like {:text, "..."}, {:expression, operand, function, attrs}, {:complex, declarations, body}, {:match, selectors, variants}, etc.

Summary

Functions

Formats a parsed MF2 AST with the given bindings.

Functions

format_list(ast, bindings \\ %{}, options \\ [])

@spec format_list(list() | tuple(), map() | Keyword.t(), Keyword.t()) ::
  {:ok, list(), list(), list()} | {:error, list(), list(), list()}
@spec format_list(term(), map() | list(), Keyword.t()) ::
  {:ok, list(), list(), list()}
  | {:error, list(), list(), list()}
  | {:format_error, String.t()}

Formats a parsed MF2 AST with the given bindings.

Arguments

  • ast is a parsed MF2 message AST as returned by Cldr.Message.V2.Parser.parse/1.

  • bindings is a map or keyword list of variable bindings. String keys are NFC-normalized to match parser output.

  • options is a keyword list of options including :backend and :locale.

Returns

  • {:ok, iolist, bound, unbound} on success, where bound is the list of variable names that were resolved and unbound is empty.

  • {:error, iolist, bound, unbound} when one or more variables could not be resolved. The iolist contains a partial result.