Skip to content

Commit

Permalink
feat: add doc comments to keys
Browse files Browse the repository at this point in the history
  • Loading branch information
chenasraf committed Dec 8, 2023
1 parent 3093957 commit 62b6e7a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/src/i18n_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,40 @@ void renderTranslation(Translation translation, StringBuffer output) {
final className = meta.nest(prefix).objectName.convertName();
output.writeln('\t$className get $keyName => $className(this);');
} else {
final comment = _wrapWithComments(v);
if (k.contains('(')) {
// function
output.writeln('\tString $keyName => """$v""";');
output.writeln('\t$comment\n\tString $keyName => """$v""";');
} else {
output.writeln('\tString get $keyName => """$v""";');
output.writeln('\t$comment\n\tString get $keyName => """$v""";');
}
}
});
output.writeln('}');
}

String _wrapWithComments(dynamic obj) {
final text = obj?.toString();
if (text == null || text.isEmpty) {
return '';
}
final lines = text.split('\n');
final output = StringBuffer();
final isMultiline = lines.length > 1;
if (isMultiline) {
lines.insert(0, '"""');
lines.add('"""');
output.writeln('/// ```dart');
for (final line in lines) {
output.writeln('/// $line');
}
output.writeln('/// ```');
} else {
output.writeln('/// `$text`');
}
return output.toString().trimRight();
}

void prepareTranslationList(
List<Translation> translations,
YamlMap messages,
Expand Down Expand Up @@ -203,3 +226,4 @@ void renderMapEntries(YamlMap messages, StringBuffer output, String prefix) {
String _renderFileNameError(String name) {
return 'File name can not contain more than 2 "_" characters: \'$name\'';
}

0 comments on commit 62b6e7a

Please sign in to comment.