IcuMessage class
ICU MessageFormat 1 interpolation, cardinal plural and select messages.
Pass numbers as numbers and include other branches. Selectordinal, date/number skeletons, MessageFormat 2 and rich-text rendering are not implemented.
Gallery walkthrough · browser route /#/localization.
These examples use the current checkout; published 1.x APIs can differ.
Interpolate named parameters
import 'package:activity/activity.dart';
void main() {
final message = IcuMessage('Hello {name}');
assert(
message.format(locale: 'en', parameters: {'name': 'Ada'}) == 'Hello Ada',
);
}
Format a cardinal plural
import 'package:activity/activity.dart';
void main() {
final message = IcuMessage(
'{count, plural, =0{No tasks} one{# task} other{# tasks}}',
);
assert(message.format(locale: 'en', parameters: {'count': 2}) == '2 tasks');
}
Select a message branch
import 'package:activity/activity.dart';
void main() {
final message = IcuMessage(
'{role, select, editor{Can edit} other{Read only}}',
);
assert(
message.format(locale: 'en', parameters: {'role': 'guest'}) == 'Read only',
);
}
Constructors
- IcuMessage(String pattern)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
format(
{required String locale, Map< String, Object?> parameters = const {}}) → String -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited