praekeltfoundation / jspot

Extracts gettext strings from Javascript files into pot files
BSD 3-Clause "New" or "Revised" License
12 stars 2 forks source link

Dynamic value for ngettext #14

Closed JSteunou closed 9 years ago

JSteunou commented 10 years ago

I have an issue with ngettext when I use it like that:

gtt.ngettext('Connected user', 'Connected users', users.length)
Running "jspot" task
Warning: on line 322 of file 'src/controller.js' users is not defined Use --force to continue.

Why evaluate possible variable inside xgettext call?

This should be skipped because the pot just need the singular & plural key.

justinvdm commented 10 years ago

Ah, thanks for this. This isn't a trivial fix unfortunately :/ Will fix this asap.

justinvdm commented 10 years ago

s/asap/as soon as I get time

JSteunou commented 10 years ago

I'm closing this, the issue is solved and published.

JSteunou commented 9 years ago

I re-open this because I find a bug. I missed a case in my PR :(

Simple variable are escaped, but not expression.

this.gettext.ngettext('foo', 'foos', length);
this.gettext.ngettext('foo', 'foos', foo.length);

1st works, 2nd does not.

justinvdm commented 9 years ago

@JSteunou ah thanks for catching this, I'm surprised we haven't run into this yet.

If I remember correctly, we wrap the last value in a function, so its body is never evaluated, so I'm confused about why the 2nd case doesn't work. Maybe we are only looking for identifiers in the AST and not things like member expressions?

JSteunou commented 9 years ago

Exactly ;) PR submited

justinvdm commented 9 years ago

wow, you've already submitted a fix while I'm busy taking guesses :) thanks, taking a look