Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String templates are not parsed #52

Open
anisimov74 opened this issue Mar 2, 2022 · 2 comments
Open

String templates are not parsed #52

anisimov74 opened this issue Mar 2, 2022 · 2 comments

Comments

@anisimov74
Copy link

anisimov74 commented Mar 2, 2022

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();
@lukasgeiter
Copy link
Owner

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.

@anisimov74
Copy link
Author

@lukasgeiter I see. Thank you for the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants