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
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.
- hasWarnings → bool
Were there any warnings or errors in extracting messages.read-only
- suppressWarnings → bool
If this is true, print warnings for skipped messages. Otherwise, warnings are suppressed.read / write
- warnings → List<String>
This accumulates a list of all warnings/errors we have found. These are saved as strings right now, so all that can really be done is print and count them.read / write
- warningsAreErrors → bool
If this is true, then treat all warnings as errors.read / write
File file) → Map<String, MainMessage>
Parse the source of the Dart program file
fileand return a Map from message names to
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.
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.
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.
Exceptions / Errors
Exception thrown when we cannot process a message properly.