1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor');
const path = require('path');
const extractor = new GettextExtractor();
const outputPotFile = path.resolve(__dirname, '../locales/messages.pot');
const comments = {
otherLineLeading: true,
sameLineLeading: true,
regex: /^TRANSLATORS:\s*(.*)$/,
};
extractor
.createJsParser([
JsExtractors.callExpression('messages.gettext', {
arguments: {
text: 0,
},
comments,
}),
JsExtractors.callExpression('messages.pgettext', {
arguments: {
context: 0,
text: 1,
},
comments,
}),
JsExtractors.callExpression('messages.ngettext', {
arguments: {
text: 0,
textPlural: 1,
},
comments,
}),
JsExtractors.callExpression('messages.npgettext', {
arguments: {
context: 0,
text: 1,
textPlural: 2,
},
comments,
}),
])
.parseFilesGlob('./src/**/*.@(ts|tsx)', {
cwd: path.resolve(__dirname, '..'),
});
// clean file references
extractor.getMessages().forEach((msg) => {
msg.references = [];
});
extractor.savePotFile(outputPotFile);
extractor.printStats();
|