Localize.Message.MF1.Sigils (Localize MF1 v0.1.0)

Copy Markdown View Source

The ~M sigil, which returns a message in canonical form at compile time.

A message may be laid out with white space for readability, but Gettext uses the message string as its key, so a change of layout would make a new message. ~M returns the canonical form of the message (Localize.Message.MF1.canonical_message/2) instead, and a message that cannot be parsed is a compile error.

This is the ~M of Cldr.Message.Sigil from ex_cldr_messages, with the same output. A MessageFormat 2 message is canonicalized by Localize.Message.canonical_message/2. Localize.Message.Sigils defines its own ~M for MF2 messages, so import one or the other.

Summary

Functions

Returns an MF1 message in canonical form.

Functions

sigil_M(arg, modifiers)

(macro)

Returns an MF1 message in canonical form.

The message is pretty printed by default, with each selector clause on a line of its own, which translators find easier to read.

Arguments

  • message is the sigil's text, without interpolation or escapes.

  • modifiers are the sigil's modifiers.

Modifiers

  • p pretty prints the message (the default).

  • u returns the message on one line.

Returns

  • The canonical message, as a string literal.

Examples

iex> import Localize.Message.MF1.Sigils
iex> ~M(An ICU message)
"An ICU message"
iex> ~M"{n, plural, other {# items} one {# item}}"u
"{n, plural, one {# item} other {# items}}"