This commit is contained in:
Ruben Vermeersch 2017-03-09 07:45:14 +01:00
parent d30a02f3c2
commit 3324041669
2 changed files with 38 additions and 4 deletions

40
dist/pofile.js vendored
View File

@ -117,7 +117,9 @@ PO.parse = function (data) {
}
});
var item = new PO.Item();
var parsedPluralForms = PO.parsePluralForms(po.headers['Plural-Forms']);
var nplurals = parsedPluralForms.nplurals;
var item = new PO.Item({ nplurals: nplurals });
var context = null;
var plural = 0;
var obsoleteCount = 0;
@ -131,7 +133,7 @@ PO.parse = function (data) {
obsoleteCount = 0;
noCommentLineCount = 0;
po.items.push(item);
item = new PO.Item();
item = new PO.Item({ nplurals: nplurals });
}
}
@ -237,7 +239,26 @@ PO.parse = function (data) {
return po;
};
PO.Item = function () {
PO.parsePluralForms = function (pluralFormsString) {
var results = (pluralFormsString || '')
.split(';')
.reduce(function (acc, keyValueString) {
var trimmedString = keyValueString.trim();
var equalsIndex = trimmedString.indexOf('=');
var key = trimmedString.substring(0, equalsIndex).trim();
var value = trimmedString.substring(equalsIndex + 1).trim();
acc[key] = value;
return acc;
}, {});
return {
nplurals: results.nplurals,
plural: results.plural
};
};
PO.Item = function (options) {
var nplurals = options && options.nplurals;
this.msgid = '';
this.msgctxt = null;
this.references = [];
@ -247,6 +268,8 @@ PO.Item = function () {
this.extractedComments = [];
this.flags = {};
this.obsolete = false;
var npluralsNumber = Number(nplurals);
this.nplurals = (isNaN(npluralsNumber)) ? 2 : npluralsNumber;
};
PO.Item.prototype.toString = function () {
@ -319,10 +342,21 @@ PO.Item.prototype.toString = function () {
['msgctxt', 'msgid', 'msgid_plural', 'msgstr'].forEach(function (keyword) {
var text = self[keyword];
if (text != null) {
var hasTranslation = false;
if (Array.isArray(text)) {
hasTranslation = text.some(function (text) {
return text;
});
}
if (Array.isArray(text) && text.length > 1) {
text.forEach(function (t, i) {
lines = lines.concat(mkObsolete + _process(keyword, t, i));
});
} else if (self.msgid_plural && keyword === 'msgstr' && !hasTranslation) {
for (var pluralIndex = 0; pluralIndex < self.nplurals; pluralIndex++) {
lines = lines.concat(mkObsolete + _process(keyword, '', pluralIndex));
}
} else {
var index = (self.msgid_plural && Array.isArray(text)) ?
0 :

2
dist/pofile.min.js vendored

File diff suppressed because one or more lines are too long