How to use the pofile 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 parachvte / vue-i18n-xgettext / src / extractor.js View on Github external
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) {
github drd / jsxlate / src / io.js View on Github external
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();
        },
github Boulangerie / angular-translate-extract / src / adapter / pot-adapter.js View on Github external
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)
github lingui / js-lingui / packages / cli / src / api / formats / po.js View on Github external
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())
  },

pofile

Parse and serialize Gettext PO files.

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis