message static method
Use this for a message that will be translated for different locales. The expected usage is that this is inside an enclosing function that only returns the value of this call and provides a scope for the variables that will be substituted in the message.
The messageText
is the string to be translated, which may be
interpolated based on one or more variables.
The args
is a list containing the arguments of the enclosing function.
If there are no arguments, args
can be omitted.
The name
is required only for messages that have args
, and optional
for messages without args
. It is used at runtime to look up the message
and pass the appropriate arguments to it. If provided, name
must be
globally unique in the program. It must match the enclosing function name,
or if the function is a method of a class, name
can also be of the form
The desc
provides a description of the message usage.
The examples
is a const Map of examples for each interpolated variable.
For example
String hello(String yourName) => Intl.message(
'Hello, $yourName',
name: 'hello',
args: [yourName],
desc: 'Say hello',
examples: const {'yourName': 'Sparky'},
);
The source code will be processed via the analyzer to extract out the
message data, so only a subset of valid Dart code is accepted. In
particular, everything must be literal and cannot refer to variables
outside the scope of the enclosing function. The examples
map must be a
valid const literal map. Similarly, the desc
argument must be a single,
simple string and skip
a boolean literal. These three arguments will not
be used at runtime but will be extracted from the source code and used as
additional data for translators. For more information see the "Messages"
section of the main
package documentation
(https://pub.dev/packages/intl).
The skip
arg will still validate the message, but will be filtered from
the extracted message output. This can be useful to set up placeholder
messages during development whose text aren't finalized yet without having
the placeholder automatically translated.
Implementation
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
// We want to try to inline these messages, but not inline the internal
// messages, so it will eliminate the descriptions and other information
// not needed at runtime.
static String message(String messageText,
{String? desc = '',
Map<String, Object>? examples,
String? locale,
String? name,
List<Object>? args,
String? meaning,
bool? skip}) =>
_message(messageText, locale, name, args, meaning);