intl_message library

This provides classes to represent the internal structure of the arguments to Intl.message. It is used when parsing sources to extract messages or to generate code for message substitution. Normal programs using Intl would not import this library.

While it's written in a somewhat abstract way, it has some assumptions about ICU-style message syntax for parameter substitutions, choices, selects, etc.

For example, if we have the message plurals(num) => Intl.message("""${Intl.plural(num, zero : 'Is zero plural?', one : 'This is singular.', other : 'This is plural ($num).') }""", name: "plurals", args: num, desc: "Basic plurals"); That is represented as a MainMessage which has only one message component, a Plural, but also has a name, list of arguments, and a description. The Plural has three different clauses. The zero clause is a LiteralString containing 'Is zero plural?'. The other clause is a CompositeMessage containing three pieces, a LiteralString for 'This is plural (', a VariableSubstitution for num. amd a LiteralString for '.)'.

This representation isn't used at runtime. Rather, we read some format from a translation file, parse it into these objects, and they are then used to generate the code representation above.

Classes

ComplexMessage
Abstract class for messages with internal structure, representing the main Intl.message call, plurals, and genders.
CompositeMessage
This represents a message chunk that is a list of multiple sub-pieces, each of which is in turn a Message.
Gender
Represents a message send of Intl.gender inside a message that is to be internationalized. This corresponds to an ICU message syntax "select" with "male", "female", and "other" as the possible options.
LiteralString
Represents a simple constant string with no dynamic elements.
MainMessage
Message
An abstract superclass for Intl.message/plural/gender calls in the program's source text. We assemble these into objects that can be used to write out some translation format and can also print themselves into code.
Plural
Select
Represents a message send of Intl.select inside a message that is to be internationalized. This corresponds to an ICU message syntax "select" with arbitrary options.
SubMessage
An abstract class to represent sub-sections of a message, primarily plurals and genders.
VariableSubstitution
Represents an interpolation of a variable value in a message. We expect this to be specified as an index into the list of variables, or else as the name of a variable that exists in arguments and we will compute the variable name or the index based on the value of the other.

Constants

jsonEncoder → const JsonCodec

Exceptions / Errors

IntlMessageExtractionException
Exception thrown when we cannot process a message properly.