message method

String message (String message_str, { String desc: '', Map<String, dynamic> examples: const {}, String locale, String name, List args, String meaning, bool skip })

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 message_str is the string to be translated, which may be interpolated based on one or more variables. The name of the message must match the enclosing function name. For methods, it can also be className_methodName. So for a method hello in class Simple, the name can be either "hello" or "Simple_hello". The name must also be globally unique in the program, so the second form can make it easier to distinguish messages with the same name but in different classes.

The args repeats the arguments of the enclosing function, desc provides a description of usage, examples is a Map of examples for each interpolated variable. For example

  hello(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.dartlang.org/packages/intl).

For messages without parameters, both name and args can be omitted. Messages that supply args should also supply a unique name. The name and args arguments used at runtime to look up the localized version and pass the appropriate arguments to it. We may in the future modify the code during compilation to make manually passing those arguments unnecessary in more situations.

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

static String message(String message_str,
        {String desc: '',
        Map<String, dynamic> examples: const {},
        String locale,
        String name,
        List args,
        String meaning,
        bool skip}) =>
    _message(message_str, locale, name, args, meaning);