gettext-extractor icon indicating copy to clipboard operation
gettext-extractor copied to clipboard

String templates are not parsed

Open anisimov74 opened this issue 2 years ago • 2 comments

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();

anisimov74 avatar Mar 02 '22 21:03 anisimov74

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 avatar Mar 03 '22 06:03 lukasgeiter

@lukasgeiter I see. Thank you for the information.

anisimov74 avatar Mar 03 '22 12:03 anisimov74