BloomCatalog class
A localized message catalog storing translated templates for a single BCP-47 locale.
Stores translation message templates indexed by message ID and evaluates them
using ICU MessageFormat syntax in pure Dart. Supports variable interpolation,
pluralization with # count replacement, select/gender branching, nested sub-patterns,
number formatting, and date formatting.
Fully source- and syntax-compatible with server-side packages/bloom_i18n.
Supported ICU MessageFormat Syntax
- Variable Interpolation:
{name}substitutesargs['name']. - Escaped Characters: Two consecutive single quotes
''emit a single quote'. Quoted brace blocks such as'{escaped}'prevent interpolation and emit{escaped}. - Plurals:
{count, plural, =0 {No items} =1 {One item} other {# items}}. Exact numeric matches (=0,=1,=2, etc.) take precedence over keyword branches (zero,one,two,other). The#character within a plural branch is automatically replaced by the localized number representation via formatNumber. - Select & Gender:
{gender, select, female {She liked} male {He liked} other {They liked}}. - Number Formatting:
{amount, number, currency}or{rate, number, percent}. - Date Formatting:
{date, date, short},{date, date, medium},{date, date, long},{date, date, full}, or custom token patterns like{date, date, yyyy-MM-dd}.
final catalog = BloomCatalog('en-US', {
'greeting': 'Hello, {name}!',
'cart_items': '{count, plural, =0 {Cart is empty} =1 {1 item} other {# items}}',
});
final text = catalog.get('cart_items', args: {'count': 3}); // "3 items"
See also:
- BloomI18n, the reactive multi-catalog translation store.
- formatNumber, formatCurrency, and formatDate for standalone formatting.
Constructors
-
BloomCatalog(String locale, Map<
String, String> messages) - Creates a BloomCatalog from a map of message IDs to ICU-formatted message templates.
-
BloomCatalog.fromJson(String locale, Map<
String, dynamic> json) -
Creates a BloomCatalog from a dynamic map, converting values to strings.
factory
- BloomCatalog.fromJsonString(String locale, String jsonString)
-
Creates a BloomCatalog by decoding a JSON-encoded string.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- locale → String
-
The BCP-47 language tag identifying the locale of this catalog (e.g.
'en-US','fr-FR','de').final -
messages
→ Map<
String, String> -
Returns an unmodifiable view of all registered message template strings.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
get(
String messageId, {Map< String, Object> ? args}) → String? -
Looks up and evaluates an ICU MessageFormat template by
messageId. -
has(
String messageId) → bool -
Returns
trueif this catalog contains a template defined formessageId. -
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