react-gettext icon indicating copy to clipboard operation
react-gettext copied to clipboard

how to generate the '.pot' file?

Open hxrealm opened this issue 7 years ago • 2 comments

when I run the program, please help me. I don't know how to generate the '.pot' file?

hxrealm avatar Jan 06 '18 07:01 hxrealm

Hey @hankewins,

have you seen cli command in the README section for POEdit? Did it help or you still have troubles?

eugene-manuilov avatar Jan 08 '18 08:01 eugene-manuilov

@hankewins If you don't want to use Poedit, its pretty easy using just node.

The POT files can be generated using gettext-extractor package. I created a gettext_extract.js file with the following:

const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor');

let extractor = new GettextExtractor();

extractor
  .createJsParser([
    JsExtractors.callExpression('getText', {
      arguments: {
        text: 0,
        context: 1
      }
    }),
    JsExtractors.callExpression(['this.context.gettext', '[this].translations.get'], {
      arguments: {
        text: 0,
        context: 2
      }
    }),
    JsExtractors.callExpression('getPlural', {
      arguments: {
        text: 1,
        textPlural: 2,
        context: 3
      }
    })
  ])
  .parseFilesGlob('./src/**/*.@(ts|js|tsx|jsx)');

extractor
  .createHtmlParser([
    HtmlExtractors.elementContent('translate, [translate]')
  ])
  .parseFilesGlob('./src/**/*.html');

extractor.savePotFile('./messages.pot');

extractor.printStats();

dcholth avatar Apr 24 '18 17:04 dcholth