from method

Message from(
  1. Object value,
  2. Message parent
)

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);
    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;
  mustBeAMessage.parent = parent;
  return mustBeAMessage;
}