Cldr.Message.Sigil (Cldr Messages v0.13.2) View Source

Implements sigil ~M to canonicalize an ICU message.

ICU messages allow for whitespace to be used to format the message for developer and translator readability. At the same time, gettext uses the message string as a key when resolving translations.

Therefore a developer or translator that modifies the message for readability may unintentionally create a new message rather than replace the old one simply because the message strings don't match exactly.

It is possible to use the fuzzy option to the task mix gettext.extract however this may not be the desired behaviour either.

The sigil ~M therefore introduces a way for the developer to ensure the message is in a canonical format during compilation and therefore both error check the message format and ensure the message is in a canonical form irrespective of developer formatting.

Link to this section Summary

Functions

Handles the sigil ~M for ICU message strings.

Link to this section Functions

Link to this macro

sigil_M(arg, modifiers)

View Source (macro)

Handles the sigil ~M for ICU message strings.

It returns a a canonically formatted string without interpolations and without escape characters, except for the escaping of the closing sigil character itself.

A canonically formatted string is pretty-printed by default returning a potentially multi-line string. This is intended to produce a result which is easier to comprehend for translators.

The modifier u can be applied to return a non-pretty-printed string.

Modifi

Examples

iex> ~m(An ICU message)
"An ICU message"

However, if you want to re-use the sigil character itself on the string, you need to escape it:

iex> ~M((\))
"()"