コード例 #1
0
  }),
};

const parser = new XGettext({
  keywords,
  parseOptions: {
    plugins: ['jsx', 'flow', 'dynamicImport', 'classProperties'],
    sourceType: 'unambiguous',
  },
});

for (currentFile of argv._) {
  currentFile = path.resolve(process.cwd(), currentFile);
  const fp = fs.readFileSync(currentFile);
  try {
    parser.getMatches(fp.toString('utf-8'));
  } catch (err) {
    console.error(`Error parsing ${JSON.stringify(currentFile)}:`);
    throw err;
  }
}

console.log(
  gettextParser.po
    .compile(potFile, {
      sort: function (a, b) {
        return msgOrdering.get(a) - msgOrdering.get(b);
      },
    })
    .toString('utf-8')
);
コード例 #2
0
            PO.load('../../ogs/ogs/go_app/locale/django.pot', (err, po) => {
                if (err) {
                    console.error(err);
                    return;
                }
                let po_items = {};
                let ui_only_keys = {};
                for (let item of po.items) {
                    let key = item.msgctxt ? item.msgctxt + '\x04' : '';
                    key += item.msgid;
                    if (item.msgid_plural) {
                        key += '\x05' + item.msgid_plural;
                    }
                    item.extractedCommentsHash = {};
                    po_items[key] = item;
                }


                for (let m of parser.getMatches( source )) {
                    if (m.msgid == "") {
                        console.log(m);
                        continue;
                    }
                    if (!m.msgid) {
                        /* this happens when a translation function is called with a non-string parameter */
                        continue;
                    }

                    let key = m.msgctxt ? m.msgctxt + '\x04' : '';
                    key += m.msgid;
                    if (m.msgid_plural) {
                        key += '\x05' + m.msgid_plural;
                    }

                    ui_only_keys[key] = 1;

                    if (!(key in po_items)) {
                        po_items[key] = new PO.Item();
                        po_items[key].extractedCommentsHash = {};
                        po.items.push(po_items[key]);
                    }
                    let item = po_items[key];

                    item.msgctxt = m.msgctxt || null;
                    item.msgid = m.msgid;
                    item.msgid_plural = m.msgid_plural || null;
                    item.references.push(m.source.source.replace(/^.*\/src\/(.*)$/, '$1') + ':' + m.source.line);

                    if (m.comment && !(m.comment in item.extractedCommentsHash)) {
                        item.extractedCommentsHash[m.comment] = m.comment;
                        item.extractedComments.push(m.comment);
                    }
                }

                fs.writeFile('build/ogs-ui-keys.json', JSON.stringify(ui_only_keys), ()=>console.log('build/ogs-ui-keys.json written'));
                po.save('build/ogs.pot', () => { console.info('Wrote ogs.pot!')} );

                for (let item of po.items) {
                    if (!item.msgid) {
                        console.error('')
                        console.error('')
                        console.error('SOURCE ERROR')
                        console.error(item);
                        console.error('')
                        console.error('')
                        continue;
                    }
                }

                for (let item of po.items) {
                    if (!item.msgid) {
                        continue;
                    }
                    item.msgstr[0] = item.msgid;
                    if (item.msgid_plural) {
                        item.msgstr[1] = item.msgid_plural;
                    }
                }

                po.save('locale/en.po', () => {
                    console.info('Wrote locale_en.po!');
                });


                for (let item of po.items) {
                    if (!item.msgid) {
                        continue;
                    }
                    item.msgstr[0] = pseudo_translate(item.msgid);
                    if (item.msgid_plural) {
                        item.msgstr[1] = pseudo_translate(item.msgid_plural);
                    }
                }

                po.save('locale/debug.po', () => {
                    console.info('Wrote locale_debug.po!');
                });
            });