toOriginalCode method

String toOriginalCode({
  1. bool includeDesc = true,
  2. dynamic includeExamples = true,
})

Create a string that will recreate this message, optionally including the compile-time only information desc and examples.

Implementation

String toOriginalCode({bool includeDesc = true, includeExamples = true}) {
  var out = StringBuffer()..write("Intl.message('");
  out.write(expanded(turnInterpolationBackIntoStringForm));
  out.write("', ");
  out.write("name: '$name', ");
  out.write(locale == null ? "" : "locale: '$locale', ");
  if (includeDesc) {
    out.write(
      description == null
          ? ""
          : "desc: '${escapeAndValidateString(description!)}', ",
    );
  }
  if (includeExamples) {
    // json is already mostly-escaped, but we need to handle interpolations.
    var json = jsonEncoder.encode(examples).replaceAll(r"$", r"\$");
    out.write(examples.isEmpty ? "" : "examples: const $json, ");
  }
  out.write(
    meaning == null
        ? ""
        : "meaning: '${escapeAndValidateString(meaning!)}', ",
  );
  out.write("args: [${arguments.join(', ')}]");
  out.write(")");
  return out.toString();
}