How to use the pofile.parse 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 gabegorelick / gulp-angular-gettext / test / main.js View on Github external
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);

          done();
        });
      });
github gamejolt / frontend-lib / gulp / plugins / gulp-split-translations.js View on Github external
this.push(file);
				return callback();
			}

			var content = file.contents.toString();
			var parsed = JSON.parse(content);
			var lang = Object.keys(parsed)[0];

			var poContent = fs.readFileSync(
				path.resolve(
					__dirname,
					'../../../site-translations/' + lang + '/main.po'
				),
				'utf8'
			);
			var poParsed = pofile.parse(poContent);
			var poItems = _.indexBy(poParsed.items, 'msgid');

			_.forEach(
				sections,
				function(sectionPaths, sectionName) {
					var sectionReferenceRegex = new RegExp(
						'^(' + sectionPaths.join('|') + ')'
					);
					var sectionJson = {};
					sectionJson[lang] = {};

					// For each translation term in this language.
					for (var i in parsed[lang]) {
						var poItem = poItems[i];
						if (poItem) {
							var matchingReferences = 0;
github drd / jsxlate / test / test-io.js View on Github external
it('outputs po files with source references', function() {
                const poSrc = io.po.out(outputFixture);
                const parsed = PO.parse(poSrc);
                parsed.items.forEach(item => {
                    const fixture = outputFixture[item.msgid];
                    expect(fixture.length).to.equal(item.references.length);
                    expect(item.references).to.eql(
                        fixture.map(({sourceFile, line}) => `${sourceFile}:${line}`)
                    );
                });
            });
        });
github rubenv / angular-gettext-tools / test / extract_complete.js View on Github external
function testExtract(filenames, options) {
    var extractor = new Extractor(options);
    filenames.forEach(function (filename) {
        extractor.parse(filename, fs.readFileSync(filename, "utf8"));
    });
    return PO.parse(extractor.toString());
}
github gabegorelick / gulp-angular-gettext / test / main.js View on Github external
stream.on('data', function (file) {
            callCount++;
            expect(callCount).to.be.gte(1)
              .and.to.be.lte(2);

            if (callCount === 1) {
              expect(file.path).to.equal(path.join(fixturesDir, 'partial1.pot'));
              expect(PO.parse(file.contents.toString())).to.deep.equal(expected1);
              return;
            }

            expect(file.path).to.equal(path.join(fixturesDir, 'partial2.pot'));
            expect(PO.parse(file.contents.toString())).to.deep.equal(expected2);

            done();
          });
github plone / volto / src / i18n.js View on Github external
function syncPoByPot() {
  const pot = Pofile.parse(fs.readFileSync('locales/volto.pot', 'utf8'));

  map(glob('locales/**/*.po'), filename => {
    const po = Pofile.parse(fs.readFileSync(filename, 'utf8'));

    fs.writeFileSync(
      filename,
      `${formatHeader(po.comments, po.headers)}
${map(pot.items, item => {
        const poItem = find(po.items, { msgid: item.msgid });
        return [
          `${map(item.references, ref => `#: ${ref}`).join('\n')}`,
          `msgid "${item.msgid}"`,
          `msgstr "${poItem ? poItem.msgstr : ''}"`,
        ].join('\n');
      }).join('\n\n')}\n`,
    );
github plone / volto / src / i18n.js View on Github external
map(glob('locales/**/*.po'), filename => {
    let { items } = Pofile.parse(fs.readFileSync(filename, 'utf8'));
    const lib = `node_modules/@plone/volto/${filename}`;
    if (fs.existsSync(lib)) {
      const libItems = Pofile.parse(fs.readFileSync(lib, 'utf8')).items;
      items = [...libItems, ...items];
    }
    const lang = filename.match(/locales\/(.*)\/LC_MESSAGES\//)[1];
    fs.writeFileSync(
      `locales/${lang}.json`,
      JSON.stringify(
        zipObject(
          map(items, item => item.msgid),
          map(
            items,
            item => (item.msgstr[0] !== '' ? item.msgstr[0] : item.msgid),
          ),
        ),
      ),
    );
  });
github ckeditor / ckeditor5-dev / packages / ckeditor5-dev-utils / lib / translations / createdictionaryfrompofilecontent.js View on Github external
module.exports = function createDictionaryFromPoFileContent( poFileContent ) {
	const po = PO.parse( poFileContent );

	const keys = {};

	for ( const item of po.items ) {
		if ( item.msgstr[ 0 ] ) {
			keys[ item.msgid ] = item.msgstr[ 0 ];
		}
	}

	return keys;
};
github guardiangg / http-client / client / tools / gettext-compiler.js View on Github external
fs.readFile(task.file, function (err, data) {
            if (err) throw err;

            var catalog = po.parse(data.toString());
            strings[catalog.headers.Language] = {};

            _.each(catalog.items, function (term) {
                strings[catalog.headers.Language][term.msgid] = term.msgstr.length === 1 ? term.msgstr[0] : term.msgstr;
            });

            callback();
        });
    });

pofile

Parse and serialize Gettext PO files.

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis