WritePOTVisitor function

POTVisitor WritePOTVisitor (Logger logger, File file)

Writes the POT-File

Implementation

POTVisitor WritePOTVisitor(final Logger logger, final File file) {
    return (final List<CommentStatement> comments,
        final List<L10NStatement> statements) {

        final StringBuffer buffer = new StringBuffer();

        comments.forEach((final CommentStatement statement) {
            final List<String> lines = statement.comment.split(new RegExp(r"\n"));
            lines.forEach((final String line) {
                buffer.writeln("#. ${line.trimLeft()}");
            });
        });
        statements.forEach((final L10NStatement statement) {
            buffer.writeln("#: ${statement.filename}:${statement.line}");
        });

        // All Statements have the same msgid - so we pick the first one
        final L10NStatement statement = statements.first;

        buffer.writeln('msgid "${statement.msgid}"');

        if(statement.params.length > 1) {
            buffer.writeln('msgid_plural "${statement.params[1]}"');
        }

        buffer.writeln('msgstr ""');
        buffer.writeln();

        logger.fine(buffer.toString().replaceFirst(new RegExp(r"\n$"), ""));
        file.writeAsStringSync(buffer.toString(),mode: FileMode.writeOnlyAppend,flush: true);
        };
    }