intlSelect method

String intlSelect(
  1. Object choice, {
  2. String? desc,
  3. Map<String, Object>? examples,
  4. String? locale,
  5. String? name,
  6. List<Object>? args,
  7. String? meaning,
  8. bool? skip,
})

Format a message differently depending on choice.

We look up the value of choice in cases and return the result, or an empty string if it is not found. Normally used as part of an Intl.message message that is to be translated.

It is possible to use a Dart enum as the choice and as the key in cases, but note that we will process this by truncating toString() of the enum and using just the name part. We will do this for any class or strings that are passed, since we can't actually identify if something is an enum or not.

choice: The choice used to select the appropriate message.

desc: A description of the message for translators.

examples: Map of example values for each possible choice to aid translators.

locale: The locale in which the message should be formatted.

name: An optional name to identify this message.

args: Optional list of arguments to be inserted into the message.

meaning: An optional meaning to disambiguate different usages of the same message.

skip: Whether the message should be skipped for translation.

Returns the formatted message corresponding to the provided choice, or an empty string if not found.

Example:

final messages = {
  'apples': 'You have $apples apples',
  'oranges': 'You have $oranges oranges',
  'bananas': 'You have $bananas bananas',
};

final fruitCount = {'apples': 5, 'oranges': 2, 'bananas': 3};

print(messages.intlSelect('apples', args: [fruitCount['apples']])); // Output: "You have 5 apples"
print(messages.intlSelect('pears')); // Output: ""

Implementation

String intlSelect(
  Object choice, {
  String? desc,
  Map<String, Object>? examples,
  String? locale,
  String? name,
  List<Object>? args,
  String? meaning,
  bool? skip,
}) {
  return Intl.select(
    choice,
    this,
    desc: desc,
    examples: examples,
    locale: locale,
    name: name,
    args: args,
    meaning: meaning,
    skip: skip,
  );
}