Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
string = string.trim();
if (string.length === 0) {
return;
}
if (!context) {
context = noContext;
}
if (!this.strings[string] || typeof this.strings[string] !== 'object') {
this.strings[string] = {};
}
if (!this.strings[string][context]) {
this.strings[string][context] = new Po.Item();
}
var item = this.strings[string][context];
item.msgid = string;
var refString = reference.file;
if (this.options.lineNumbers && reference.location && reference.location.start) {
var line = reference.location.start.line;
if (line || line === 0) {
refString += ':' + reference.location.start.line;
}
}
var refIndex = search(item.references, refString, stringCompare);
if (refIndex < 0) { // don't add duplicate references
// when not found, binary-search returns -(index_where_it_should_be + 1)
item.references.splice(Math.abs(refIndex + 1), 0, refString);
string = string.trim();
if (string.length === 0) {
return;
}
if (!context) {
context = noContext;
}
if (!this.strings[string] || typeof this.strings[string] !== 'object') {
this.strings[string] = {};
}
if (!this.strings[string][context]) {
this.strings[string][context] = new Po.Item();
}
var item = this.strings[string][context];
item.msgid = string;
var refString = reference.file;
if (this.options.lineNumbers && reference.location && reference.location.start) {
var line = reference.location.start.line;
if (line || line === 0) {
refString += ':' + reference.location.start.line;
}
}
var refIndex = search(item.references, refString, stringCompare);
if (refIndex < 0) { // don't add duplicate references
// when not found, binary-search returns -(index_where_it_should_be + 1)
item.references.splice(Math.abs(refIndex + 1), 0, refString);
R.mapObjIndexed((message, key) => {
const item = new PO.Item()
item.msgid = key
item.msgstr = message.translation
item.comments = message.comments || []
item.extractedComments = message.description ? [message.description] : []
item.references = message.origin ? message.origin.map(joinOrigin) : []
item.obsolete = message.obsolete
item.flags = message.flags
? R.fromPairs(message.flags.map(flag => [flag, true]))
: {}
return item
})
)
}
/*
Check for an existing item.
*/
let existing = result.items.find(item => item.msgid === string);
if (existing) {
existing.references.push(location);
if (comment) {
existing.extractedComments.push(comment);
}
} else {
let item = new poFile.Item();
item.msgid = string;
item.msgid_plural = pluralString;
item.references = [location];
if (pluralString) {
item.msgstr = ['', ''];
}
if (comment) {
item.extractedComments = [comment];
}
result.items.push(item);
}
}
function toPoItem(withLineNumbers = false) {
let poItem = new Pofile.Item();
poItem.msgid = this.msgid;
poItem.msgid_plural = this.plural;
poItem.references = [ this.reference.toString(withLineNumbers) ];
poItem.msgctxt = this.msgctxt;
poItem.msgstr = [];
return poItem;
}
function toPoItem(withLineNumbers = false) {
let poItem = new Pofile.Item();
poItem.msgid = this.msgid;
poItem.msgid_plural = this.plural;
poItem.references = [ this.reference.toString(withLineNumbers) ];
poItem.msgctxt = this.msgctxt === MARKER_NO_CONTEXT ? null : this.msgctxt;
poItem.msgstr = [];
return poItem;
}
toPoItem(withLineNumbers = false) {
let poItem = new Pofile.Item();
poItem.msgid = this.text;
poItem.msgctxt = this.msgctxt === constants.MARKER_NO_CONTEXT ? null : this.msgctxt;
poItem.references = [this.reference.toString(withLineNumbers)];
poItem.msgid_plural = this.plural;
poItem.msgstr = this.plural ? ['', ''] : [];
poItem.extractedComments = this.comment ? [this.comment] : [];
return poItem;
}
};
/*
Check for an existing item.
*/
let existing = result.items.find(item => item.msgid === string);
if (existing) {
existing.references.push(location);
if (comment) {
existing.extractedComments.push(comment);
}
}
else {
let item = new poFile.Item();
item.msgid = string;
item.msgid_plural = pluralString;
item.references = [location];
if (pluralString) {
item.msgstr = ['', ''];
}
if (comment) {
item.extractedComments = [comment];
}
result.items.push(item);
}
}
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();