Django

Code

Ticket #4695 (closed: fixed)

Opened 3 years ago

Last modified 1 month ago

xgettext skips some translation strings in javascript files

Reported by: voy@voy.cz Assigned to: ramiro
Milestone: 1.2 Component: Internationalization
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by mtredinnick)

For a simple Javascript source file like this:

// '
gettext("foo");
// '
gettext("bar");

results of make-messages.py 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

4695-javascript-makemessages-fix.diff (3.1 kB) - added by ramiro on 02/02/10 15:53:06.
Fix by seveas plus tests

Change History

06/26/07 05:26:49 changed by voy@voy.cz

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Sorry for the broken new lines.

// '
gettext("foo");
// '
gettext("bar");

06/26/07 07:20:38 changed by mtredinnick

  • description changed.

Fixed description.

12/01/07 19:38:31 changed by Simon G <dev@simon.net.nz>

  • stage changed from Unreviewed to Accepted.

04/29/09 11:01:23 changed by dc

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

// '
gettext("foo");
# '
gettext("bar");

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

r'\n\s*//'

and will not match at the beginning of the file.

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

07/12/09 11:49:08 changed by seveas

  • has_patch set to 1.
  • version changed from 0.96 to SVN.

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

Index: core/management/commands/makemessages.py
===================================================================
--- core/management/commands/makemessages.py	(revision 11227)
+++ core/management/commands/makemessages.py	(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',)):
     """

02/02/10 15:53:06 changed by ramiro

  • attachment 4695-javascript-makemessages-fix.diff added.

Fix by seveas plus tests

02/02/10 15:58:45 changed 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.

02/10/10 12:40:17 changed by ramiro

  • owner changed from nobody to ramiro.
  • milestone set to 1.2.

02/16/10 06:13:24 changed by jezdez

  • status changed from new to closed.
  • resolution set to fixed.

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

02/16/10 06:51:43 changed 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.


Add/Change #4695 (xgettext skips some translation strings in javascript files)




Change Properties
Action