MessageSelectFormatter

Select a text value based on the value of the parameter.

Format:

{ PARAMETER_NUMBER, select, VALUE1  {TEXT1} VALUE2 VALUE3 {TEXT2} /VALUE_REGEX/ {TEXT3} other {OTHERWISE_TEXT} }
  • PARAMETER_NUMBER:

    • Number of the parameter which value is matched against the values of the select list

  • VALUE*:

    • If a values matches the value of the parameter, the corresponding text (TEXT*) is selected

    • List of several values for the same text can be listed before the next text element

  • VALUE_REGEX

    • When the value is prefixed and suffixed by "/", it is seen as regular repression, e.g. /([A-Z])\w+/

    • If the regex matches the value of the parameter, the corresponding text (TEXT3) is selected

  • TEXT*:

    • Text that is returned by the pattern if the value matches the value of the parameter

    • Texts themselves can also contain patterns. So, the patterns can be nested.

  • OTHERWISE_TEXT

    • If none of the values before matched, this text will be selected

    • If there is no OTHERWISE_TEXT specified and no value matches, an empty string is returned

Values and texts are trimmed (leading and tailing whitespaces are removed)

Example:

{0} has forgotten {1, select, female {her} other {his} } {3, select, one {bag} other {{2} bags}}.

Usage:

FORGOTTEN_BAG("Peter", "male", 1, "one")
-> Peter has forgotten his bag.
FORGOTTEN_BAG("Mary", "female", 2, "few")
-> Mary has forgotten her 2 bags.

Properties

Link copied to clipboard
open override val typeId: String

ID of the type of the formatter

Link copied to clipboard

True if typeId is just a prefix for the type.

Functions

Link copied to clipboard
open override fun format(result: StringBuilder, value: Any?, typeId: CharSequence, style: StylePart?, parameters: MessageParameters, locale: Locale, context: MessageFormatContext)

Formats the given value and writes is to result.