How to use pofile - 10 common examples

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 gabegorelick / gulp-angular-gettext / test / main.js View on Github external
stream.on('data', function (file) {
        expect(file.path).to.equal(path.join(fixturesDir, 'foo.bar'));

        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);
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 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 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 / 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();
          });

pofile

Parse and serialize Gettext PO files.

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis