Comparing version 1.0.3 to 1.0.5
@@ -117,3 +117,5 @@ var fs = require('fs'); | ||
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; | ||
@@ -132,3 +134,3 @@ var plural = 0; | ||
po.items.push(item); | ||
item = new PO.Item(); | ||
item = new PO.Item({ nplurals: nplurals }); | ||
} | ||
@@ -239,3 +241,22 @@ } | ||
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 = ''; | ||
@@ -250,2 +271,4 @@ this.msgctxt = null; | ||
this.obsolete = false; | ||
var npluralsNumber = Number(nplurals); | ||
this.nplurals = (isNaN(npluralsNumber)) ? 2 : npluralsNumber; | ||
}; | ||
@@ -323,2 +346,9 @@ | ||
if (text != null) { | ||
var hasTranslation = false; | ||
if (Array.isArray(text)) { | ||
hasTranslation = text.some(function (text) { | ||
return text; | ||
}); | ||
} | ||
if (Array.isArray(text) && text.length > 1) { | ||
@@ -328,2 +358,6 @@ text.forEach(function (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 { | ||
@@ -330,0 +364,0 @@ var index = (self.msgid_plural && Array.isArray(text)) ? |
{ | ||
"name": "pofile", | ||
"description": "Parse and serialize Gettext PO files.", | ||
"version": "1.0.3", | ||
"version": "1.0.5", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Ruben Vermeersch", |
@@ -146,3 +146,3 @@ # pofile - gettext .po parsing for JavaScript | ||
Copyright (C) 2013-2014 by Ruben Vermeersch <ruben@rocketeer.be> | ||
Copyright (C) 2013-2017 by Ruben Vermeersch <ruben@rocketeer.be> | ||
Copyright (C) 2012 by Michael Holly | ||
@@ -149,0 +149,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20428
372