From 0d4f80e7f6634d3d7f816b28fbd9ebd906718f34 Mon Sep 17 00:00:00 2001 From: Ruben Vermeersch Date: Tue, 17 Dec 2013 16:35:40 +0100 Subject: [PATCH] Write flags out when serializing. --- lib/po.js | 5 +++++ test/write.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/write.js diff --git a/lib/po.js b/lib/po.js index b140e12..4a7fe88 100644 --- a/lib/po.js +++ b/lib/po.js @@ -193,6 +193,11 @@ PO.Item.prototype.toString = function () { }); } + var flags = Object.keys(this.flags); + if (flags.length > 0) { + lines.push(util.format('#, %s', flags.join(","))); + } + ['msgid', 'msgid_plural', 'msgstr'].forEach(function (keyword) { var text = that[keyword]; if (text != null) { diff --git a/test/write.js b/test/write.js new file mode 100644 index 0000000..0c0f610 --- /dev/null +++ b/test/write.js @@ -0,0 +1,26 @@ +var assert = require('assert'); +var fs = require('fs'); +var PO = require('..'); + +function assertHasLine(str, line) { + var lines = str.split("\n"); + var found = false; + + for (var i = 0; i < lines.length; i++) { + if (lines[i].trim() === line) { + found = true; + break; + } + } + + assert(found, "Could not find line: " + line); +} + +describe('Write', function () { + it('write flags', function () { + var input = fs.readFileSync(__dirname + '/fixtures/fuzzy.po', 'utf8'); + var po = PO.parse(input); + var str = po.toString(); + assertHasLine(str, "#, fuzzy"); + }); +});