from static method
Turn a value, typically read from a translation file or created out of an AST for a source program, into the appropriate subclass. We expect to get literal Strings, variable substitutions represented by integers, things that are already MessageChunks and lists of the same.
Implementation
static Message from(Object value, Message? parent) {
if (value is String) return new LiteralString(value, parent);
if (value is int) return new VariableSubstitution(value, parent);
if (value is List) {
if (value.length == 1) return Message.from(value[0], parent);
var result = new CompositeMessage([], parent as ComplexMessage?);
var items = value.map((x) => from(x, result)).toList();
result.pieces.addAll(items);
return result;
}
// We assume this is already a Message.
Message mustBeAMessage = value as Message;
mustBeAMessage.parent = parent;
return mustBeAMessage;
}