Error converting some files
arelstone opened this issue · 0 comments
arelstone commented
I am trying to convert all our old .po files to .json and it works fine for almost all the files but two. se_SV.po
and nb_NO.po
All .po files are identical but the msgstr
key
Script:
var path = require('path');
var fs = require('fs');
var shell = require('shelljs');
function fromDir(startPath, filter) {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return;
}
var files = fs.readdirSync(startPath);
for (var i = 0; i < files.length; i++) {
var filename = path.join(startPath, files[i]);
var stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
fromDir(filename, filter); //recurse
}
else if (filename.indexOf(filter) >= 0) {
const split = filename.split('/')[1].split('.')[0]
//console.log(split)
const string = './node_modules/.bin/po2json ' + filename + ' ./locale/json/'+split+'.json -f mf -p'
console.log("Converting", filename, "to json format")
shell.exec(string)
}
}
}
fromDir('locale', '.po');
Error:
/path/to/my/repo/node_modules/gettext-parser/lib/poparser.js:393
table.headers = sharedFuncs.parseHeader(tokens[i].msgstr[0]);
^
TypeError: Cannot read property '0' of undefined
at Parser._normalize (/path/to/my/repo/node_modules/gettext-parser/lib/poparser.js:393:69)
at Parser._finalize (/path/to/my/repo/node_modules/gettext-parser/lib/poparser.js:414:17)
at Parser.parse (/path/to/my/repo/node_modules/gettext-parser/lib/poparser.js:63:17)
at Object.module.exports.parse (/path/to/my/repo/node_modules/gettext-parser/lib/poparser.js:17:19)
at module.exports (/path/to/my/repo/node_modules/po2json/lib/parse.js:27:45)
at Object.module.exports [as parseFileSync] (/path/to/my/repo//node_modules/po2json/lib/parseFileSync.js:14:28)
at Object.<anonymous> (/path/to/my/repo//node_modules/po2json/bin/po2json:50:22)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
.po-file header
I've tries with the file header from #30 but still doesn't work
"Project-Id-Version: messages\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-08-03 16:00+0100\n"
"PO-Revision-Date: 2015-08-09 22:06+0100\n"
"Last-Translator: NAME <email@address.com>\n"
"Language-Team: NAME <email@address.com>\n"
"Language: sv\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.1\n"