formatMessage static method
Evaluates an ICU MessageFormat template string with args for the specified locale.
Supports argument interpolation {name}, plurals {count, plural, ...} with # replacement,
select {gender, select, ...}, number formatting {amount, number, currency}, and date
formatting {date, date, short} in pure Dart without dependencies on package:intl.
final result = BloomCatalog.formatMessage(
'You have {count, plural, =0 {no messages} =1 {one message} other {# messages}}',
args: {'count': 5},
locale: 'en-US',
);
// result: "You have 5 messages"
See also:
- get, which looks up a template by key before formatting.
Implementation
static String formatMessage(
String template, {
Map<String, Object>? args,
String? locale,
}) {
if (args == null || args.isEmpty) {
if (!template.contains('{')) {
return template;
}
}
return _IcuMessageFormatter(locale: locale).format(template, args ?? const {});
}