-
Notifications
You must be signed in to change notification settings - Fork 0
Message Syntax
Kenny Mochizuki Escalona edited this page Aug 16, 2026
·
1 revision
Use {key} markers to insert plain-text arguments into messages:
// Message: 'Hello, {name}!'
i18n.t('greeting', {'name': 'Alice'})
// Result: 'Hello, Alice!'Use [key] markers to insert rich text arguments (resolved to InlineSpan):
// Message: 'Click [link]'
i18n.te('prompt', richArgs: {
'link': TextSpan(
text: 'here',
style: TextStyle(color: Colors.blue),
),
})
// Result: TextSpan with clickable blue "here"Use | (space-pipe-space) to separate singular and plural forms:
// Message: 'One item | {count} items'
i18n.tc('items', 1, {}) // Result: 'One item'
i18n.tc('items', 5, {'count': '5'}) // Result: '5 items'| Method | Input | Returns | Purpose |
|---|---|---|---|
t(key, args) |
key and plain args | String |
Translate with plain-text arguments |
tc(key, count, args) |
key, count, and plain args | String |
Pluralize and translate with plain-text arguments |
te(key, args, richArgs, style) |
key, plain args, rich args, style | TextSpan |
Translate with rich-text arguments |
tce(key, count, args, richArgs, style) |
key, count, plain args, rich args, style | TextSpan |
Pluralize and translate with rich-text arguments |
If an argument is not provided, the literal marker is rendered:
// Message: 'Hello, {name}!'
i18n.t('greeting', {})
// Result: 'Hello, {name}!'If an argument value is null, the string "null" is rendered:
// Message: 'Hello, {name}!'
i18n.t('greeting', {'name': null})
// Result: 'Hello, null!'If count is null, the t() method returns the ENTIRE string including both forms separated by |:
// Message: 'One item | {count} items'
i18n.t('items') // Returns raw message: 'One item | {count} items'
i18n.tc('items', null, {}) // Same: 'One item | {count} items'Use tc() or tce() to select a plural form; they treat null count as non-singular (plural form used).
Arguments are interpolated within each form, not across the separator:
// Message: 'One {object} | {count} {objects}'
i18n.tc('count', 5, {'object': 'apple', 'count': '5', 'objects': 'apples'})
// Result: '5 apples'Plural splitting happens BEFORE argument interpolation, so | in argument values do not break the split.
Made with ❤️ by Golden M, Inc.