Opened 4 years ago

Closed 4 years ago

#15495 closed Bug (fixed)

makemessages excludes all strings from Javascript after a comment

Reported by: lrekucki Owned by: nedbatchelder
Component: Internationalization Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

A sample code (shortened as much as possible, the original comment was something like "get/set doesn't ...", so it's not synthetic):

/* / ' */ gettext("TEXT");

xgettext doesn't find any translations after the shown comment. Removing either / or ' fixes the problem. This is a bit related to #4695.

Attachments (1)

ticket15495.diff (7.2 KB) - added by lrekucki 4 years ago.
A bit naive patch with tests.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 4 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from {{{makemessages}}} excludes all strings from Javascript after a comment to makemessages excludes all strings from Javascript after a comment

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by lrekucki

A bit naive patch with tests.

comment:3 Changed 4 years ago by lrekucki

  • Has patch set

The patch fixes this particular problem (and some similar to it), but it's not too hard to construct a valid JavaScript that gets omited or improperly mangled by regexps. Just a few examples:

gettext("String"); // This comment won't be caught by pythonize_re and it contains "'" which is a string start in Perl
/* 
 * This one will be removed by the patch
 */
gettext("/* but this one will be too */ 'cause there is no way of telling...");
f(/* ... if it's different from this one */);

The only real fix is having a JavaScript lexer and (probaly simplified) parser instead of a bunch of hacky regexps. No time to do it right now, so maybe someone else wants to do it.

comment:4 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 4 years ago by nedbatchelder

  • Owner changed from nobody to nedbatchelder
  • Status changed from new to assigned

comment:6 Changed 4 years ago by julien

  • Patch needs improvement set

Patch needs improvement as per Łukasz's comment above.

comment:7 Changed 4 years ago by nedbatchelder

Yes, I'm working on a real patch to include a Javascript lexer.

comment:8 Changed 4 years ago by nedbatchelder

Patch attached to #7704 fixes this problem.

comment:9 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from assigned to closed

In [16333]:

Fixed #7704, #14045 and #15495 -- Introduce a lexer for Javascript to fix multiple problems of the translation of Javascript files with xgettext. Many thanks to Ned Batchelder for his contribution of the JsLex library.

Note: See TracTickets for help on using tickets.
Back to Top