add reverse method of extract(string)
during PO.parse, an extract(string) method is called on each string to unescape some characters (like " and \). This process should be reverted in the toString method. The PO spec says, that all strings should be C-Strings. Otherwise tools like msgmerge (from the gettext package) will fail parsing po files written by this library.
This commit is contained in:
10
lib/po.js
10
lib/po.js
@@ -181,6 +181,12 @@ PO.Item.prototype.toString = function () {
|
||||
var lines = [],
|
||||
that = this;
|
||||
|
||||
// reverse what extract(string) method during PO.parse does
|
||||
var _escape = function (string) {
|
||||
string = string.replace(/\\/g, '\\\\');
|
||||
return string.replace(/"/g, '\\"');
|
||||
};
|
||||
|
||||
var _process = function (keyword, text, i) {
|
||||
var lines = [],
|
||||
parts = text.split(/\n/),
|
||||
@@ -188,11 +194,11 @@ PO.Item.prototype.toString = function () {
|
||||
if (parts.length > 1) {
|
||||
lines.push(keyword + index + ' ""');
|
||||
parts.forEach(function (part) {
|
||||
lines.push('"' + part + '"');
|
||||
lines.push('"' + _escape(part) + '"');
|
||||
});
|
||||
}
|
||||
else {
|
||||
lines.push(keyword + index + ' "' + text + '"');
|
||||
lines.push(keyword + index + ' "' + _escape(text) + '"');
|
||||
}
|
||||
return lines;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user