gettext-extractor
gettext-extractor copied to clipboard
String templates are not parsed
Thank you for the module you've created.
I have a problem with generating a .pot file for the code like
i18nPlural(issuesAmount, `${issuesAmount} issue`, `${issuesAmount} issues`)
.
i18nPlural is implemented with the node-gettext
No plural form generated. Please advise.
Full source code of the extractor
const { GettextExtractor, JsExtractors } = require('gettext-extractor');
const fs = require('fs');
const dir = './translations';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
const extractor = new GettextExtractor();
extractor
.createJsParser([
JsExtractors.callExpression('i18n', {
arguments: {
text: 0,
context: 1,
},
}),
JsExtractors.callExpression('i18nPlural', {
arguments: {
text: 1,
textPlural: 2,
context: 3,
},
}),
])
.parseFilesGlob('./src/**/!(*.spec).js');
extractor.savePotFile('./translations/default.pot');
extractor.printStats();
Variable substitutions in template strings are not supported. From the wiki:
Note: Template literals are supported, but only without placeholders. Since the string containing placeholders isn't available during runtime those can't be used for translations anyway.
I believe with node-gettext you should be using %d
as a placeholder for the count.
@lukasgeiter I see. Thank you for the information.