Skip to content

Commit 3f3fbd1

Browse files
authored
Merge pull request #29 from chenasraf/feat/doc-strings
feat: add doc comments to keys
2 parents b4469ff + fc1d91f commit 3f3fbd1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/src/i18n_impl.dart

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
library i18n;
22

3+
import 'dart:convert';
4+
35
import 'package:yaml/yaml.dart';
46

57
import 'metadata.dart';
@@ -157,6 +159,8 @@ void renderTranslation(Translation translation, StringBuffer output) {
157159
final className = meta.nest(prefix).objectName.convertName();
158160
output.writeln('\t$className get $keyName => $className(this);');
159161
} else {
162+
final comment = _wrapWithComments(v);
163+
output.writeln(comment);
160164
if (k.contains('(')) {
161165
// function
162166
output.writeln('\tString $keyName => """$v""";');
@@ -168,6 +172,28 @@ void renderTranslation(Translation translation, StringBuffer output) {
168172
output.writeln('}');
169173
}
170174

175+
String _wrapWithComments(dynamic obj) {
176+
final text = obj?.toString();
177+
if (text == null || text.isEmpty) {
178+
return '';
179+
}
180+
final lines = LineSplitter().convert(text);
181+
final output = StringBuffer();
182+
final isMultiline = lines.length > 1;
183+
output.writeln('/// ```dart');
184+
if (isMultiline) {
185+
output.writeln('/// """');
186+
for (final line in lines) {
187+
output.writeln('/// $line');
188+
}
189+
output.writeln('/// """');
190+
} else {
191+
output.writeln('/// "$text"');
192+
}
193+
output.writeln('/// ```');
194+
return output.toString().trimRight();
195+
}
196+
171197
void prepareTranslationList(
172198
List<Translation> translations,
173199
YamlMap messages,
@@ -203,3 +229,4 @@ void renderMapEntries(YamlMap messages, StringBuffer output, String prefix) {
203229
String _renderFileNameError(String name) {
204230
return 'File name can not contain more than 2 "_" characters: \'$name\'';
205231
}
232+

0 commit comments

Comments
 (0)