How to use the pofile.Item function in pofile

To help you get started, we’ve selected a few pofile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rubenv / angular-gettext-tools / lib / extract.js View on Github external
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);
github rubenv / angular-gettext-tools / lib / extract.js View on Github external
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);
github lingui / js-lingui / packages / cli / src / api / formats / po.js View on Github external
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
  })
)
github klembot / twinejs / scripts / extract-pot.js View on Github external
}

	/*
	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);
	}
}
github Polyconseil / easygettext / src / node-translation-representation-factory.js View on Github external
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;
}
github Polyconseil / easygettext / src / javascript-extract.js View on Github external
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;
}
github Polyconseil / easygettext / src / extract.js View on Github external
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;
  }
};
github klembot / twinejs / scripts / extract-pot.js View on Github external
/*
	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);
	}
}
github drd / jsxlate / src / io.js View on Github external
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();

pofile

Parse and serialize Gettext PO files.

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis