Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ yarn add --dev easygettext
##### HTML token extraction

Simply invoke the tool on the templates you want to extract a POT dictionary template from.
The optional '--ouput' argument enables you to directly output to a file.
The optional '--output' argument enables you to directly output to a file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should document somewhere that we now support something more, don't you think ?


```
gettext-extract --output dictionary.pot foo.html bar.pug component.vue sourcefile.js
Expand Down
65 changes: 15 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"gettext-extract": "./src/extract-cli.js"
},
"dependencies": {
"@babel/core": "^7.7.5",
"@vue/component-compiler-utils": "^2.6.0",
"acorn": "^6.4.0",
"acorn-stage3": "^2.0.0",
Expand Down
9 changes: 5 additions & 4 deletions src/extract-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const extraAttribute = argv.attribute || false;
const extraFilter = argv.filter || false;
const removeHTMLWhitespaces = argv.removeHTMLWhitespaces || false;
const filterPrefix = argv.filterPrefix || constants.DEFAULT_FILTER_PREFIX;
const jsParser = argv.parser || 'auto';

if (!quietMode && (!files || files.length === 0)) {
console.log('Usage:\n\tgettext-extract [--attribute EXTRA-ATTRIBUTE] [--filterPrefix FILTER-PREFIX] [--output OUTFILE] <FILES>');
console.log('Usage:\n\tgettext-extract [--attribute EXTRA-ATTRIBUTE] [--filterPrefix FILTER-PREFIX] [--output OUTFILE] [--parser auto|acorn|babel] <FILES>');
process.exit(1);
}

Expand Down Expand Up @@ -63,7 +64,7 @@ files.forEach(function(filename) {
console.log(`[${PROGRAM_NAME}] will not extract: '${filename}' (invalid extension)`);
return;
}
console.log(`[${PROGRAM_NAME}] extracting: '${filename}`);
console.log(`[${PROGRAM_NAME}] extracting: '${filename}'`);
try {
let data = fs.readFileSync(file, {encoding: 'utf-8'}).toString();
extractor.parse(file, extract.preprocessTemplate(data, ext));
Expand All @@ -80,10 +81,10 @@ files.forEach(function(filename) {
}

if (lang === 'js') {
extractor.parseJavascript(file, data);
extractor.parseJavascript(file, data, jsParser);
}
} catch (e) {
console.error(`[${PROGRAM_NAME}] could not read: '${filename}`);
console.error(`[${PROGRAM_NAME}] could not read: '${filename}' using parser ${jsParser}`);
console.trace(e);
process.exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ exports.Extractor = class Extractor {
}
}

parseJavascript(filename, content) {
parseJavascript(filename, content, parser='auto') {
const jsContent = flowRemoveTypes(content).toString();

const extractedStringsFromScript = jsExtractor.extractStringsFromJavascript(filename, jsContent);
const extractedStringsFromScript = jsExtractor.extractStringsFromJavascript(filename, jsContent, parser);

this.processStrings(extractedStringsFromScript);
}
Expand Down
Loading