extract_messages library

This is for use in extracting messages from a Dart program using the Intl.message() mechanism and writing them to a file for translation. This provides only the stub of a mechanism, because it doesn't define how the file should be written. It provides an IntlMessage class that holds the extracted data and parseString and parseFile methods which can extract messages that conform to the expected pattern: (parameters) => Intl.message("Message $parameters", desc: ...); It uses the analyzer package to do the parsing, so may break if there are changes to the API that it provides. An example can be found in test/message_extraction/extract_to_json.dart

Note that this does not understand how to follow part directives, so it has to explicitly be given all the files that it needs. A typical use case is to run it on all .dart files in a directory.

Classes

InterpolationVisitor
Given an interpolation, find all of its chunks, validate that they are only simple variable substitutions or else Intl.plural/gender calls, and keep track of the pieces of text so that other parts of the program can deal with the simple string sections and the generated parts separately. Note that this is a SimpleAstVisitor, so it only traverses one level of children rather than automatically recursing. If we find a plural or gender, which requires recursion, we do it with a separate special-purpose visitor.
MessageExtraction
A particular message extraction run. [...]
MessageFindingVisitor
This visits the program source nodes looking for Intl.message uses that conform to its pattern and then creating the corresponding IntlMessage objects. We have to find both the enclosing function, and the Intl.message invocation.
PluralAndGenderVisitor
A visitor to extract information from Intl.plural/gender sends. Note that this is a SimpleAstVisitor, so it doesn't automatically recurse. So this needs to be called where we expect a plural or gender immediately below.

Functions

computeMessageName(String name String text String meaning) → String
If a message is a string literal without interpolation, compute a name based on that and the meaning, if present.

Typedefs

OnMessage(String message) → void
A function that takes a message and does something useful with it.