toOriginalCode method
Create a string that will recreate this message, optionally including the compile-time only information desc and examples.
Implementation
String toOriginalCode({
bool includeDesc = true,
bool 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: '${Message.escapeString(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: '${Message.escapeString(meaning!)}', ",
);
out.write("args: [${arguments.join(', ')}]");
out.write(')');
return out.toString();
}