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

Copy Markdown View Source

NIF wrapper for ICU4C MessageFormat 2.0.

Provides validate/1 and format/3 functions that delegate to ICU's MessageFormatter implementation. The NIF is optional — when unavailable, available?/0 returns false and calls raise :nif_library_not_loaded.

Summary

Functions

Returns true if the MF2 NIF is loaded and available.

Formats a MessageFormat 2 message string using ICU.

Validates a MessageFormat 2 message string using ICU's parser.

Functions

available?()

@spec available?() :: boolean()

Returns true if the MF2 NIF is loaded and available.

format(message, locale \\ "en", args \\ %{})

@spec format(String.t(), String.t(), map()) ::
  {:ok, String.t()} | {:error, String.t()}

Formats a MessageFormat 2 message string using ICU.

Arguments are passed as a map of %{name => value} and encoded to JSON for the NIF.

Returns {:ok, formatted_string} or {:error, reason}.

validate(message)

@spec validate(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Validates a MessageFormat 2 message string using ICU's parser.

Returns {:ok, normalized_pattern} or {:error, reason}.