Skip to content
New issue

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

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

Already on GitHub? # to your account

ngettext with a regular string #281

Open
uladzimirdev opened this issue Feb 23, 2024 · 2 comments
Open

ngettext with a regular string #281

uladzimirdev opened this issue Feb 23, 2024 · 2 comments

Comments

@uladzimirdev
Copy link

Hi, I couldn't find the answer from the code, so maybe you can help me to understand how to handle such simple case

ngettext(msgid`record`, "records", n);

babel plugin doesn't like such strings and raises an error

at template2Msgid (/node_modules/babel-plugin-ttag/dist/utils.js:116:32)
at /node_modules/babel-plugin-ttag/dist/extractors/ngettext.js:55:38

is it a bug or just unexpected usage? is there any workaround?

@uladzimirdev uladzimirdev changed the title ngettext with a regular sting ngettext with a regular string Feb 23, 2024
@AlexMost
Copy link
Member

AlexMost commented Feb 23, 2024

Hi, seems like a bug. As a temporary workaround you can try to use

ngettext(msgid`record`, `records`, n);

The most frequent case for ngettext is when n is present in the translated string like

ngettext(msgid`${ n } record`, `${ n } records`, n);

But I agree that your example should also work fine. Will take a look at this case ASAP.

@uladzimirdev
Copy link
Author

fair enough, I had this problem only because of eslint quotes rule, which replaced backticks with double quotes as there wasn't any parameter inside.

Thanks for confirming

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants