Internationalization
Trellis supports internationalized messages through #{...} message expressions
backed by a MessageSource.
#{...} – message expressions
Use #{key} to look up a message by key. Positional arguments are passed in
parentheses and fill the placeholders {0}, {1}, and so on in the message:
<p tl:text="#{welcome.title}">Welcome</p>
<p tl:text="#{greeting(${user.name})}">Hello, user!</p>
Wiring up a MessageSource
Provide a MessageSource and a default locale when constructing the engine.
MapMessageSource is a simple in-memory implementation:
Trellis(
messageSource: MapMessageSource(messages: {
'en': {
'welcome.title': 'Welcome to Trellis',
'greeting': 'Hello, {0}!',
},
'es': {
'welcome.title': 'Bienvenido a Trellis',
'greeting': '¡Hola, {0}!',
},
}),
locale: 'en', // default locale; override per-request via the _locale context key
);
- Positional placeholders
{0},{1}, … are replaced by the arguments passed in the expression. - Override the locale per render by setting the
_localekey in the context. - A missing key returns the key itself in lenient mode, or throws in strict mode.