python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.3k stars 433 forks source link

Extractor: Support translation string not being the first argument #72

Open jacobsvante opened 10 years ago

jacobsvante commented 10 years ago

I'm working on a project using jed for translating strings in my javascript. Its ifPlural function takes the translation string as its second argument. Would it be possible to support this? One could make the lexer check for the first argument that is a string, but that feels kinda guess:y. Perhaps a better way would be to add new syntax like this:

$ pybabel -k translate -k ifPlural:2

Where :2 is the position of the argument that contains the string to translate. If left out the first function argument is used.

torfsen commented 8 years ago

I think using the first string argument would be a real improvement and a useful heuristic. It's certainly not worse than the existing solution (which seems to just simply ignore the call) and probably a lot less work than extending the keyword-specification syntax.

Support for something like ifPlural:2 can then be added later on (if it is required at all).