add parsing support for msgctxt field of poitems
The gettext format specifies a msgctxt field for translated items. An example of how to use this field has been added to the tests and the parsing of this attribute has been implemented.
This commit is contained in:
parent
94ad44f953
commit
6790bfb466
@ -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 = [];
|
||||
|
10
test/fixtures/big.po
vendored
10
test/fixtures/big.po
vendored
@ -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."
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user