Opened 7 years ago

Closed 4 years ago

Last modified 3 years ago

#4695 closed (fixed)

xgettext skips some translation strings in javascript files

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

Description (last modified by mtredinnick)

For a simple Javascript source file like this:

// '
// '

results of run will exclude the "foo" string. Apparently this is related to the presence of apostrophes in the preceding comment. I am using gettext 0.14.4 under win32. I suspect this might be some quirk in relation to xgettext being called with Perl in the language parameter.

Attachments (1)

4695-javascript-makemessages-fix.diff (3.1 KB) - added by ramiro 4 years ago.
Fix by seveas plus tests

Download all attachments as: .zip

Change History (11)

comment:1 Changed 7 years ago by voy@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Sorry for the broken new lines.

// '
// '

comment:2 Changed 7 years ago by mtredinnick

  • Description modified (diff)

Fixed description.

comment:3 Changed 6 years ago by Simon G <dev@…>

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 5 years ago by dc

For this javascript makemessages runs pythonize_re and produces temporary .py file:

// '
# '

then calls xgettext to process it as perl source.

If we will ignore nonsense conversions, the problem is in pythonize_re which is defined as


and will not match at the beginning of the file.

But with all that really dirty magic the problem can be in another place.

comment:5 Changed 5 years ago by seveas

  • Has patch set
  • Version changed from 0.96 to SVN

This one-line fix against current trunk (11227) would solve the problem.

Index: core/management/commands/
--- core/management/commands/    (revision 11227)
+++ core/management/commands/    (working copy)
@@ -17,7 +17,7 @@
 # still sensible for us to use it, since subprocess didn't exist in 2.3.
 warnings.filterwarnings('ignore', category=DeprecationWarning, message=r'os\.popen3')
-pythonize_re = re.compile(r'\n\s*//')
+pythonize_re = re.compile(r'(?:^|\n)\s*//')
 def handle_extensions(extensions=('html',)):

Changed 4 years ago by ramiro

Fix by seveas plus tests

comment:6 Changed 4 years ago by ramiro

I've attached a patch that contains the simple regular expression fix described by seveas plus the beginnings of regression tests for the translatable literal extraction functionality. Hopefully we will be able to expand them with more Javascript extraction corner cases and to add template extraction cases.

comment:7 Changed 4 years ago by ramiro

  • milestone set to 1.2
  • Owner changed from nobody to ramiro

comment:8 Changed 4 years ago by jezdez

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

(In [12441]) Fixed #4695 - Worked around a problem of xgettext ignoring some translation strings in JavaScript files. Thanks, Ramiro Morales.

comment:9 Changed 4 years ago by jezdez

(In [12451]) [1.1.X] Fixed #4695 - Worked around a problem of xgettext ignoring some translation strings in JavaScript files. Thanks, Ramiro Morales.

Backport of r12441.

comment:10 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.