Cldr.Message (Cldr Messages v0.10.0) View Source

Implements the ICU Message Format with functions to parse and interpolate messages.

Link to this section Summary

Link to this section Types

Specs

arguments() :: list() | map()

Specs

message() :: binary()

Specs

options() :: Keyword.t()

Link to this section Functions

Link to this function

canonical_message(message, options \\ [])

View Source

Formats a message into a canonical form.

This allows for messages to be compared directly, or using Cldr.Message.jaro_distance/3.

Arguments

  • message is a CLDR message in binary form

  • options is a keyword list of options. The default is []

Options

  • :trim determines if the message is trimmed of whitespace before formatting. The default is true.

  • :pretty determines if the message if formatted with indentation to aid readability. The default is false.

Returns

  • {ok, canonical_message} where canonical_message is a binary or

  • {:error, {exception, reason}}

Examples

Link to this function

canonical_message!(message, options \\ [])

View Source

Formats a message into a canonical form or raises if the message cannot be parsed.

This allows for messages to be compared directly, or using Cldr.Message.jaro_distance/3.

Arguments

  • message is a CLDR message in binary form

  • options is a keyword list of options. The default is []

Options

  • :trim determines if the message is trimmed of whitespace before formatting. The default is true.

  • :pretty determines if the message if formatted with indentation to aid readability. The default is false.

Returns

  • canonical_message where canonical_message is a binary or

  • raises an exception

Examples

Link to this function

format(message, args \\ [], options \\ [])

View Source

Specs

format(String.t(), arguments(), options()) ::
  {:ok, String.t()} | {:error, {module(), String.t()}}
Link to this function

format!(message, args \\ [], options \\ [])

View Source

Specs

format!(String.t(), arguments(), options()) :: String.t() | no_return()
Link to this function

format_list(message, args, options)

View Source

See Cldr.Message.Interpreter.format_list/3.

Link to this function

jaro_distance(message1, message2, options \\ [])

View Source

Returns the Jaro distance between two messages.

This allows for fuzzy matching of message which can be helpful when a message string is changed but the semantics remain the same.

Arguments

  • message1 is a CLDR message in binary form

  • message2 is a CLDR message in binary form

  • options is a keyword list of options. The default is []

Options

  • :trim determines if the message is trimmed of whitespace before formatting. The default is false.

Returns

  • {ok, distance} where distance is a float value between 0.0 (equates to no similarity) and 1.0 (is an exact match) representing Jaro distance between message1 and message2 or

  • {:error, {exception, reason}}

Examples

Link to this function

jaro_distance!(message1, message2, options \\ [])

View Source

Returns the Jaro distance between two messages or raises.

This allows for fuzzy matching of message which can be helpful when a message string is changed but the semantics remain the same.

Arguments

  • message1 is a CLDR message in binary form

  • message2 is a CLDR message in binary form

  • options is a keyword list of options. The default is []

Options

  • :trim determines if the message is trimmed of whitespace before formatting. The default is false.

Returns

  • distance where distance is a float value between 0.0 (equates to no similarity) and 1.0 (is an exact match) representing Jaro distance between message1 and message2 or

  • raises an exception

Examples