Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
PO.load(path.join(fixturesDir, 'test.pot'), function (err, expected) {
if (err) {
done(err);
return;
}
var actual = PO.parse(file.contents.toString());
// clear file references that depend on abolute paths
var actualItems = actual.items.map(function (i) {
i.references = [];
});
var expectedItems = expected.items.map(function (i) {
i.references = [];
});
expect(actualItems).to.deep.equal(expectedItems);
done();
});
});
this.push(file);
return callback();
}
var content = file.contents.toString();
var parsed = JSON.parse(content);
var lang = Object.keys(parsed)[0];
var poContent = fs.readFileSync(
path.resolve(
__dirname,
'../../../site-translations/' + lang + '/main.po'
),
'utf8'
);
var poParsed = pofile.parse(poContent);
var poItems = _.indexBy(poParsed.items, 'msgid');
_.forEach(
sections,
function(sectionPaths, sectionName) {
var sectionReferenceRegex = new RegExp(
'^(' + sectionPaths.join('|') + ')'
);
var sectionJson = {};
sectionJson[lang] = {};
// For each translation term in this language.
for (var i in parsed[lang]) {
var poItem = poItems[i];
if (poItem) {
var matchingReferences = 0;
it('outputs po files with source references', function() {
const poSrc = io.po.out(outputFixture);
const parsed = PO.parse(poSrc);
parsed.items.forEach(item => {
const fixture = outputFixture[item.msgid];
expect(fixture.length).to.equal(item.references.length);
expect(item.references).to.eql(
fixture.map(({sourceFile, line}) => `${sourceFile}:${line}`)
);
});
});
});
function testExtract(filenames, options) {
var extractor = new Extractor(options);
filenames.forEach(function (filename) {
extractor.parse(filename, fs.readFileSync(filename, "utf8"));
});
return PO.parse(extractor.toString());
}
stream.on('data', function (file) {
callCount++;
expect(callCount).to.be.gte(1)
.and.to.be.lte(2);
if (callCount === 1) {
expect(file.path).to.equal(path.join(fixturesDir, 'partial1.pot'));
expect(PO.parse(file.contents.toString())).to.deep.equal(expected1);
return;
}
expect(file.path).to.equal(path.join(fixturesDir, 'partial2.pot'));
expect(PO.parse(file.contents.toString())).to.deep.equal(expected2);
done();
});
function syncPoByPot() {
const pot = Pofile.parse(fs.readFileSync('locales/volto.pot', 'utf8'));
map(glob('locales/**/*.po'), filename => {
const po = Pofile.parse(fs.readFileSync(filename, 'utf8'));
fs.writeFileSync(
filename,
`${formatHeader(po.comments, po.headers)}
${map(pot.items, item => {
const poItem = find(po.items, { msgid: item.msgid });
return [
`${map(item.references, ref => `#: ${ref}`).join('\n')}`,
`msgid "${item.msgid}"`,
`msgstr "${poItem ? poItem.msgstr : ''}"`,
].join('\n');
}).join('\n\n')}\n`,
);
map(glob('locales/**/*.po'), filename => {
let { items } = Pofile.parse(fs.readFileSync(filename, 'utf8'));
const lib = `node_modules/@plone/volto/${filename}`;
if (fs.existsSync(lib)) {
const libItems = Pofile.parse(fs.readFileSync(lib, 'utf8')).items;
items = [...libItems, ...items];
}
const lang = filename.match(/locales\/(.*)\/LC_MESSAGES\//)[1];
fs.writeFileSync(
`locales/${lang}.json`,
JSON.stringify(
zipObject(
map(items, item => item.msgid),
map(
items,
item => (item.msgstr[0] !== '' ? item.msgstr[0] : item.msgid),
),
),
),
);
});
module.exports = function createDictionaryFromPoFileContent( poFileContent ) {
const po = PO.parse( poFileContent );
const keys = {};
for ( const item of po.items ) {
if ( item.msgstr[ 0 ] ) {
keys[ item.msgid ] = item.msgstr[ 0 ];
}
}
return keys;
};
fs.readFile(task.file, function (err, data) {
if (err) throw err;
var catalog = po.parse(data.toString());
strings[catalog.headers.Language] = {};
_.each(catalog.items, function (term) {
strings[catalog.headers.Language][term.msgid] = term.msgstr.length === 1 ? term.msgstr[0] : term.msgstr;
});
callback();
});
});