1
1
library i18n;
2
2
3
+ import 'dart:convert' ;
4
+
3
5
import 'package:yaml/yaml.dart' ;
4
6
5
7
import 'metadata.dart' ;
@@ -157,6 +159,8 @@ void renderTranslation(Translation translation, StringBuffer output) {
157
159
final className = meta.nest (prefix).objectName.convertName ();
158
160
output.writeln ('\t $className get $keyName => $className (this);' );
159
161
} else {
162
+ final comment = _wrapWithComments (v);
163
+ output.writeln (comment);
160
164
if (k.contains ('(' )) {
161
165
// function
162
166
output.writeln ('\t String $keyName => """$v """;' );
@@ -168,6 +172,28 @@ void renderTranslation(Translation translation, StringBuffer output) {
168
172
output.writeln ('}' );
169
173
}
170
174
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
+
171
197
void prepareTranslationList (
172
198
List <Translation > translations,
173
199
YamlMap messages,
@@ -203,3 +229,4 @@ void renderMapEntries(YamlMap messages, StringBuffer output, String prefix) {
203
229
String _renderFileNameError (String name) {
204
230
return 'File name can not contain more than 2 "_" characters: \' $name \' ' ;
205
231
}
232
+
0 commit comments