diff --git a/lib/po.js b/lib/po.js index 2e0c586..0068547 100644 --- a/lib/po.js +++ b/lib/po.js @@ -139,6 +139,10 @@ PO.parse = function (data) { item.msgstr[plural] = extract(line); context = 'msgstr'; } + else if (line.match(/^msgctxt/)) { // Context + finish(); + item.msgctxt = extract(line); + } else { // Probably multiline string or blank if (line.length > 0) { if (context === 'msgstr') { @@ -160,6 +164,7 @@ PO.parse = function (data) { PO.Item = function () { this.msgid = ''; + this.msgctxt = ''; this.references = []; this.msgid_plural = null; this.msgstr = []; diff --git a/test/fixtures/big.po b/test/fixtures/big.po index d2a37a7..4638b40 100644 --- a/test/fixtures/big.po +++ b/test/fixtures/big.po @@ -285,3 +285,13 @@ msgstr "Attribut 'title' du lien" # Comment msgid "Title, as plain text" msgstr "Attribut title, en tant que texte brut" + +# Empty should be adjective +msgctxt "folder display" +msgid "Empty folder" +msgstr "This folder is empty." + +# Empty should be verb +msgctxt "folder action" +msgid "Empty folder" +msgstr "Make this folder empty." diff --git a/test/parse.js b/test/parse.js index 3996326..483f303 100644 --- a/test/parse.js +++ b/test/parse.js @@ -6,7 +6,7 @@ describe('Parse', function () { it('Parses the big po file', function () { var po = PO.parse(fs.readFileSync(__dirname + '/fixtures/big.po', 'utf8')); assert.notEqual(po, null); - assert.equal(po.items.length, 67); + assert.equal(po.items.length, 69); var item = po.items[0]; assert.equal(item.msgid, "Title"); @@ -62,4 +62,15 @@ describe('Parse', function () { assert.notEqual(item.flags, null); assert.equal(item.flags.fuzzy, true); }); + + it('Parses item context', function () { + var po = PO.parse(fs.readFileSync(__dirname + '/fixtures/big.po', 'utf8')); + + var ambiguousItems = po.items.filter(function (item) { + return item.msgid === 'Empty folder'; + }); + + assert.equal(ambiguousItems[0].msgctxt, 'folder display'); + assert.equal(ambiguousItems[1].msgctxt, 'folder action'); + }); });