gettext-parser
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -129,8 +129,20 @@ var encoding = require("encoding"), | ||
Compiler.prototype._addPOString = function(key, value){ | ||
var line = ""; | ||
key = (key || "").toString(); | ||
// escape newlines and quotes | ||
value = (value || "").toString(). | ||
replace(/\\/g, "\\\\"). | ||
replace(/\"/g, "\\\""). | ||
replace(/\r/g, "\\r"); | ||
replace(/\r/g, "\\r"). | ||
replace(/\n/g, "\\n"); | ||
var lines = sharedFuncs.foldLine(value); | ||
if(lines.length < 2){ | ||
return key + " \"" + (lines.shift() || "") + "\""; | ||
}else{ | ||
return key + " \"\"\n\"" + lines.join("\"\n\"") + "\""; | ||
} | ||
if(value.match(/\n/)){ | ||
@@ -137,0 +149,0 @@ value = value.replace(/\n/g, "\\n\n").replace(/\n$/, ""); |
@@ -6,2 +6,3 @@ | ||
module.exports.formatCharset = formatCharset; | ||
module.exports.foldLine = foldLine; | ||
@@ -74,2 +75,46 @@ /** | ||
trim(); | ||
} | ||
/** | ||
* Folds long lines according to PO format | ||
* | ||
* @param {String} str PO formatted string to be folded | ||
* @param {Number} [maxLen=76] Maximum allowed length for folded lines | ||
* @return {Array} An array of lines | ||
*/ | ||
function foldLine(str, maxLen){ | ||
maxLen = maxLen || 76; | ||
var lines = [], | ||
curLine = "", | ||
pos = 0, | ||
len = str.length, | ||
match; | ||
while(pos < len){ | ||
curLine = str.substr(pos, maxLen); | ||
// ensure that the line never ends with a partial escaping | ||
// make longer lines if needed | ||
while(curLine.substr(-1) == "\\" && pos + curLine.length < len){ | ||
curLine += str.charAt(pos + curLine.length); | ||
} | ||
// ensure that if possible, line breaks are done at reasonable places | ||
if((match = curLine.match(/\\n/))){ | ||
curLine = curLine.substr(0, match.index + 2); | ||
}else if(pos + curLine.length < len){ | ||
if((match = curLine.match(/(\s+)[^\s]*$/)) && match.index > 0){ | ||
curLine = curLine.substr(0, match.index + match[1].length); | ||
}else if((match = curLine.match(/([\x21-\x40\x5b-\x60\x7b-\x7e]+)[^\x21-\x40\x5b-\x60\x7b-\x7e]*$/)) && match.index > 0){ | ||
curLine = curLine.substr(0, match.index + match[1].length); | ||
} | ||
} | ||
lines.push(curLine); | ||
pos += curLine.length; | ||
} | ||
return lines; | ||
} |
{ | ||
"name": "gettext-parser", | ||
"description": "Parse and compile gettext po and mo files to/from json, nothing more, nothing less", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author" : "Andris Reinman", | ||
@@ -6,0 +6,0 @@ "homepage": "http://github.com/andris9/gettext-parser", |
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
60122
24
1465