Skip to content

Commit

Permalink
Merge pull request #29 from chenasraf/feat/doc-strings
Browse files Browse the repository at this point in the history
feat: add doc comments to keys
  • Loading branch information
MohiuddinM authored Dec 10, 2023
2 parents b4469ff + fc1d91f commit 3f3fbd1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/src/i18n_impl.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
library i18n;

import 'dart:convert';

import 'package:yaml/yaml.dart';

import 'metadata.dart';
Expand Down Expand Up @@ -157,6 +159,8 @@ 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);
output.writeln(comment);
if (k.contains('(')) {
// function
output.writeln('\tString $keyName => """$v""";');
Expand All @@ -168,6 +172,28 @@ void renderTranslation(Translation translation, StringBuffer output) {
output.writeln('}');
}

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

void prepareTranslationList(
List<Translation> translations,
YamlMap messages,
Expand Down Expand Up @@ -203,3 +229,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 3f3fbd1

Please sign in to comment.