Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
toPofile() {
const pofile = new Pofile()
pofile.headers = {
'Last-Translator': 'vue-i18n-xgettext',
'Content-Type': 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding': '8bit',
'MIME-Version': '1.1',
}
const itemMapping = {}
for (let translation of this.translations) {
const item = translation.toPofileItem()
if (!itemMapping[item.msgid]) {
itemMapping[item.msgid] = item
} else {
const oldItem = itemMapping[item.msgid]
// TODO: deal with plurals/context
if (item.references.length && oldItem.references.indexOf(item.references[0]) === -1) {
out(messages, {root = process.cwd(), headers = defaultHeaders} = {}) {
const po = new PO();
Object.assign(po.headers, headers);
Object.keys(messages).forEach(message => {
const items = messages[message];
const item = new PO.Item();
item.msgid = message;
item.references = items.map(
({sourceFile, line,}) => `${sourceFile.replace(root || '', '')}:${line}`
);
po.items.push(item);
});
return po.toString();
},
persist(translations) {
var catalog = new Po()
catalog.headers = {
'Content-Type': 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding': '8bit',
'Project-Id-Version': ''
}
_.forEach(translations.getFlatTranslations(), (value, msg) => {
catalog.items.push(new PotObject(msg, value))
})
catalog.items.sort(function(a, b) {
return a.id.toLowerCase().localeCompare(b.id.toLowerCase())
})
var fullPath = path.resolve(this.basePath, this.params.dest, this.params.prefix + this.params.suffix)
write(filename, catalog, options = {}) {
let po
let indexedItems = {}
if (fs.existsSync(filename)) {
const raw = fs.readFileSync(filename).toString()
po = PO.parse(raw)
} else {
po = new PO()
po.headers = getCreateHeaders(options.language)
po.headerOrder = R.keys(po.headers)
}
po.items = serialize(catalog)
fs.writeFileSync(filename, po.toString())
},