How to use the gettext-parser.po.parse function in gettext-parser

To help you get started, we’ve selected a few gettext-parser 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 rtymchyk / babel-plugin-extract-text / test / plugin.spec.js View on Github external
it('should extract 1 singular/plural string with context', () => {
        transform(
          '',
          OPTIONS
        )
        const po = poParser.parse(fs.readFileSync(TESTPO))
        assertHasPluralContextEntry(po, '1 flag', 'Many flags', 'Object')
        assertNumberOfEntries(po, 1)
      })
github rtymchyk / babel-plugin-extract-text / test / plugin.spec.js View on Github external
it('should extract 1 singular/plural string ', () => {
        transform("_n('One', 'Many', 5)", OPTIONS)
        const po = poParser.parse(fs.readFileSync(TESTPO))
        assertHasPluralEntry(po, 'One', 'Many')
        assertNumberOfEntries(po, 1)
      })
github rtymchyk / babel-plugin-extract-text / test / plugin.spec.js View on Github external
it('should extract comments', () => {
        transform(
          '', OPTIONS)
        const po = poParser.parse(fs.readFileSync(TESTPO))
        expect(po.translations['']['Hey there!'].comments.extracted).toBe('On Homepage')
        assertNumberOfEntries(po, 1)
      })
    })
github rtymchyk / babel-plugin-extract-text / test / plugin.spec.js View on Github external
it('should extract from shortform call expression', () => {
        transform("", OPTIONS)
        const po = poParser.parse(fs.readFileSync(TESTPO))
        assertHasSingularEntry(po, 'Hey {name}!')
        assertNumberOfEntries(po, 1)
      })
github rtymchyk / babel-plugin-extract-text / test / plugin.spec.js View on Github external
name: 'msgc',
                  singular: 1,
                  context: 2,
                }, {
                  type: 'PLURAL_CONTEXT',
                  name: 'msgpc',
                  singular: 1,
                  plural: 2,
                  context: 4,
                },
              ],
            }],
          ],
        }
      )
      const po = poParser.parse(fs.readFileSync(TESTPO))

      assertHasSingularEntry(po, 'Hello')
      assertHasSingularContextEntry(po, 'Block', 'Lego')
      assertHasPluralEntry(po, '1 person', '{x} people')
      assertHasPluralContextEntry(po, 'One', 'Many', 'People')
      assertNumberOfEntries(po, 4)
    })
  })
github LotusTM / Kotsu / modules / gettext.js View on Github external
const readPoMessages = (path) => {
  const file = readFileSync(path)
  return po.parse(file)
}
github i18next / i18next-gettext-converter / src / lib / gettext2json.js View on Github external
function addTextLocale(locale, body, options = {}) {
  const gt = new Gettext();
  const domain = 'messages';
  const { filter, gettextDefaultCharset = 'UTF-8' } = options;

  if (body.length > 0) {
    gt.addTranslations(locale, domain, po.parse(body, gettextDefaultCharset));
  }

  if (filter) {
    const filterAsync = Promise.promisify(filter);
    return filterAsync(gt, locale);
  }

  return Promise.resolve(
    gt.catalogs[locale] && gt.catalogs[locale][domain].translations,
  );
}
github binary-com / binary-static / scripts / gettext.js View on Github external
update_translations: () => {
            process.stdout.write(common.messageStart('Updating translations'));

            const start_time    = Date.now();
            const messages_file = Path.join(common.root_path, translations_dir, 'messages.pot');
            const content       = fs.readFileSync(messages_file, 'utf8');
            const parsed        = po.parse(content);
            const old_strings   = Object.keys(parsed.translations['']).filter(s => s);
            const old_count     = old_strings.length;
            const new_strings   = [];

            parsed.translations[''] = {};
            source_strings.sort().forEach(entry => {
                const idx = old_strings.indexOf(entry);
                if (idx === -1) {
                    new_strings.push(entry);
                } else {
                    old_strings.splice(idx, 1);
                }
                parsed.translations[''][entry] = {
                    msgid : entry,
                    msgstr: [''],
                };

gettext-parser

Parse and compile gettext po and mo files to/from json, nothing more, nothing less

MIT
Latest version published 3 months ago

Package Health Score

79 / 100
Full package analysis