Opened 9 years ago

Closed 7 years ago

Last modified 5 years ago

#4695 closed (fixed)

xgettext skips some translation strings in javascript files

Reported by: voy@… Owned by: Ramiro Morales
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 Malcolm Tredinnick)

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 (1)

4695-javascript-makemessages-fix.diff (3.1 KB) - added by Ramiro Morales 7 years ago.
Fix by seveas plus tests

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by voy@…

Sorry for the broken new lines.

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

comment:2 Changed 9 years ago by Malcolm Tredinnick

Description: modified (diff)

Fixed description.

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

Triage Stage: UnreviewedAccepted

comment:4 Changed 8 years ago 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.

comment:5 Changed 7 years ago by Dennis Kaarsemaker

Has patch: set
Version: 0.96SVN

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

  • core/management/commands/makemessages.py

     
    1717# still sensible for us to use it, since subprocess didn't exist in 2.3.
    1818warnings.filterwarnings('ignore', category=DeprecationWarning, message=r'os\.popen3')
    1919
    20 pythonize_re = re.compile(r'\n\s*//')
     20pythonize_re = re.compile(r'(?:^|\n)\s*//')
    2121
    2222def handle_extensions(extensions=('html',)):
    2323    """

Changed 7 years ago by Ramiro Morales

Fix by seveas plus tests

comment:6 Changed 7 years ago by Ramiro Morales

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 7 years ago by Ramiro Morales

milestone: 1.2
Owner: changed from nobody to Ramiro Morales

comment:8 Changed 7 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

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

comment:9 Changed 7 years ago by Jannis Leidel

(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 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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