-
Notifications
You must be signed in to change notification settings - Fork 2
/
genlocale.js
37 lines (26 loc) · 1.22 KB
/
genlocale.js
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
const glob = require("glob");
const fs = require("fs");
const { GettextExtractor } = require('gettext-extractor');
const pluralForm = require('plural-forms');
const decorateExtractorWithPlurals = require('./dist/decorateExtractorWithPlurals.js');
const callExpressionWithLiteral = require('./dist/callExpressionWithLiteral.js');
const decorateJsParserWithReplacer = require('./dist/decorateJsParserWithReplacer.js');
const config = require('./dist/config.js');
const extractor = decorateExtractorWithPlurals(new GettextExtractor());
const jsParser = extractor.createJsParser(config.optionsArray.map((el)=>{
return callExpressionWithLiteral(el.calleeNames, el.extractorOptions);
}));
const vueParser = decorateJsParserWithReplacer(jsParser);
const languageFiles = 'en';
const output = 'locale/messages.pot';
const pattern = './example/**/*.@(js|vue)';
for (let fileName of glob.sync(pattern)) {
vueParser.parseSourceFile(fs.readFileSync(fileName).toString(), fileName);
}
let npluralsFiles = pluralForm.getNPlurals(languageFiles);
let headers = {
"Plural-Forms": pluralForm.getPluralFormsHeader(languageFiles),
"Language": languageFiles
};
extractor.savePotFile(output, headers, npluralsFiles);
extractor.printStats();