Opened 16 years ago
Last modified 13 years ago
#7704 closed
JS comments put after statements break make-messages.py output — at Initial Version
Reported by: | Robby Dermody | Owned by: | nobody |
---|---|---|---|
Component: | Internationalization | Version: | 1.0 |
Severity: | Normal | Keywords: | djangojs, make-messages |
Cc: | robbyd@…, ned@…, ionel.mc@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
To test, make a JS file (say myfile.js) with the following valid JS content:
var a = 1; if(a != 2 && a != 5) //this comment breaks the file { //this does not alert(gettext("foobar")); }
Running make-messages.py -d djangojs -a will then yield the following output for that (in the myfile.js.py intermediate file it produces):
var a = 1; if(a != 2 && a != 5) //this comment breaks the file { #this does not alert(gettext("foobar")); }
As you can see, the comment after the if statement was not replaced, and since xgettext is then run in Perl mode, it seems to choke on that input. The result depends on the exact code: This example will cause only that next gettext("foobar") not to be generated (ones further down in the code will). With other code I had that had a similar line, nothing was generated. The failure is silent and the only way to know is by checking the gettext output (or lack thereof :).
This is due to the regexp in make-messages: pythonize_re = re.compile(r'\n\s*//') and then the replacement code: src = pythonize_re.sub('\n#', src)
That assumes that comments come after newlines. I'm not submitting a patch right now because I'm unsure about the best regexp to use for this that will get all the valid JS comment cases (or if that is even something the django devs want to do). At the very least, if you all choose not to address this in the code, there should be a note in the documentation telling folks to always put JS comments on their own lines.
As make-messages.py is now included in django-admin AFAIK, I've categorized it to that.