react-gettext
react-gettext copied to clipboard
how to generate the '.pot' file?
when I run the program, please help me. I don't know how to generate the '.pot' file?
Hey @hankewins,
have you seen cli command in the README section for POEdit? Did it help or you still have troubles?
@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();