Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

how to generate the '.pot' file? #17

Open
hxrealm opened this issue Jan 6, 2018 · 2 comments
Open

how to generate the '.pot' file? #17

hxrealm opened this issue Jan 6, 2018 · 2 comments
Labels

Comments

@hxrealm
Copy link

hxrealm commented Jan 6, 2018

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

@eugene-manuilov
Copy link
Owner

Hey @hankewins,

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

@dcholth
Copy link

dcholth commented Apr 24, 2018

@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();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants