From fff8349e2500bfbd347c50511ea0849cc4d2f05c Mon Sep 17 00:00:00 2001 From: Ruben Vermeersch Date: Tue, 17 Dec 2013 15:04:44 +0100 Subject: [PATCH] Parse item flags. --- lib/po.js | 8 ++++++++ test/fixtures/fuzzy.po | 20 ++++++++++++++++++++ test/parse.js | 12 ++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 test/fixtures/fuzzy.po diff --git a/lib/po.js b/lib/po.js index 6bf1bf3..b140e12 100644 --- a/lib/po.js +++ b/lib/po.js @@ -113,6 +113,13 @@ PO.parse = function (data) { finish(); item.references.push(trim(line.replace(/^#:/, ''))); } + else if (line.match(/^#,/)) { // Flags + finish(); + var flags = trim(line.replace(/^#,/, '')).split(","); + for (var i = 0; i < flags.length; i++) { + item.flags[flags[i]] = true; + } + } else if (line.match(/^#/)) { // Comment finish(); item.comments.push(trim(line.replace(/^#/, ''))); @@ -157,6 +164,7 @@ PO.Item = function () { this.msgid_plural = null; this.msgstr = []; this.comments = []; + this.flags = {}; }; PO.Item.prototype.toString = function () { diff --git a/test/fixtures/fuzzy.po b/test/fixtures/fuzzy.po new file mode 100644 index 0000000..e166523 --- /dev/null +++ b/test/fixtures/fuzzy.po @@ -0,0 +1,20 @@ +# French translation of Link (6.x-2.9) +# Copyright (c) 2011 by the French translation team +# +msgid "" +msgstr "" +"Project-Id-Version: Link (6.x-2.9)\n" +"POT-Creation-Date: 2011-12-31 23:39+0000\n" +"PO-Revision-Date: 2013-12-17 14:59+0100\n" +"Language-Team: French\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"Last-Translator: Ruben Vermeersch \n" +"Language: fr\n" +"X-Generator: Poedit 1.6.2\n" + +#, fuzzy +msgid "Sources" +msgstr "Source" diff --git a/test/parse.js b/test/parse.js index 51ee2d8..3996326 100644 --- a/test/parse.js +++ b/test/parse.js @@ -50,4 +50,16 @@ describe('Parse', function () { assert.equal(item.msgstr, "Y"); assert.deepEqual(item.references, ["a", "b"]); }); + + it('Parses flags', function () { + var po = PO.parse(fs.readFileSync(__dirname + '/fixtures/fuzzy.po', 'utf8')); + assert.notEqual(po, null); + assert.equal(po.items.length, 1); + + var item = po.items[0]; + assert.equal(item.msgid, "Sources"); + assert.equal(item.msgstr, "Source"); + assert.notEqual(item.flags, null); + assert.equal(item.flags.fuzzy, true); + }); });