Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
stream.on('data', function (file) {
expect(file.path).to.equal(path.join(fixturesDir, 'foo.bar'));
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);
#!/usr/bin/env node
const reSingular = / \(singular\)$/
, rePlural = / \(plural\)$/
require('pofile').load('/dev/stdin', (err, po) => {
if (err) throw err
const tran = po.items.filter(item => item.msgstr[0] != '' || item.msgstr.length > 1)
.reduce((T, { msgid, msgstr }) => {
if (msgstr.length && !(msgstr.length == 1 && msgid === msgstr[0])) {
const isSingular = reSingular.test(msgid), isPlural = rePlural.test(msgid)
if (isSingular || isPlural) {
const msgid_s = msgid.replace(reSingular, '').replace(rePlural, '')
T[msgid_s] || (T[msgid_s] = [])
T[msgid_s][isSingular?0:1] = msgstr[0]
} else {
T[msgid] = msgstr[0]
}
}
return T
}, {})
return new Promise((resolve, reject) => {
PO.load(filePath, (loadErr, po) => {
if (loadErr) {
console.log(loadErr);
}
const translated = [];
po.items
.filter(item => translations.includes(item.msgid))
.forEach(item => {
translated.push({
msgid: item.msgid,
msgstr: item.msgstr[0]
});
});
resolve({ lang, translated });
});
});
Lang.prototype.run = function () {
var translationData = {};
var dirs = this.dirs;
PO.load(this.poPath, function (err, po) {
if (err) throw new Error("Could not parse " + this.poPath);
po.items.forEach(function (item) {
if (!item.msgctxt) return;
var key = item.msgctxt + '__' + item.msgid;
var file = item.msgctxt.split('.')[0];
var path = item.msgctxt.split('.').slice(1);
var o = {
stringOriginal: item.msgid,
stringTranslated: item.msgstr[0],
context: item.msgctxt,
file: file,
path: path
};
translationData[file] = translationData[file] || [];
import { basename } from 'path';
import { promisify } from 'util';
import { LanguageTable, MessageTable } from '@fitbit-sdk/companion-gettext';
import { default as _glob } from 'glob';
import humanizeList from 'humanize-list';
import pofile from 'pofile';
import { dataToEsm } from 'rollup-pluginutils';
import BuildError from '../util/BuildError';
import { validateLanguageTag, supportedTags } from '../languageTag';
const glob = promisify(_glob);
const loadPOFile = promisify(pofile.load);
async function loadTranslations(filePath: string) {
const po = await loadPOFile(filePath);
const messages: MessageTable = {};
for (const { msgid, msgstr } of po.items) {
if (msgstr.length > 1) {
throw new BuildError(
`msgid "${msgid}" in file "${filePath}" has multiple msgstr values. This is not supported.`,
);
}
messages[msgid] = msgstr[0];
}
return messages;
}