Opened 5 years ago

Closed 4 years ago

#14045 closed Bug (fixed)

makemessage miss some gettext in javascript

Reported by: shaohao Owned by: nedbatchelder
Component: Internationalization Version: 1.2
Severity: Normal Keywords: xgettext
Cc: ramusus@…, ned@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:

Description

Here is a simple javascript code for testing:

function mfunc() {
    var val = 0;
    return val ? 1 : 0;
}
gettext('okkkk');
print mysub();

save it as 'result.pl'
Now run:

xgettext -d out -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "result.pl"

Ouput nothing

Change History (13)

comment:1 Changed 5 years ago by shaohao

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

If i change:

return val ? 1 : 0;

to {{{
return $val ? 1 : 0;
}}}

xgettext works.

comment:2 Changed 5 years ago by mk

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

I cannot reproduce this failure:

$ xgettext -d out -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "result.pl"
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-10-05 12:32+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: result.pl:5
msgid "okkkk"
msgstr ""

Even if this would happen this would not be a Django but a gettext bug.

comment:3 Changed 4 years ago by ramusus

  • Cc ramusus@… added

The same occured to me. After my last Ubuntu update from 9.4 to 10.10 version, makemessages command for javascripts starts to process my files incompletely. I investigate this problem deeper and come to conclusion the main reason is gettext package. It was the version 0.18.1.1-1ubuntu2. After downgrading gettext to 0.17-8ubuntu3 the problem disappeared.

I don't know is it a normal behavior of gettext or bug. I understand gettext doesn't support straight Javasript language support, but nevertheless setting "-L Perl" worried me. Is there no any other parsers for javascripts?

comment:4 Changed 4 years ago by ramusus

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I reopen ticket because. this problem may occur on some system distributions, I noticed above the reason and specification. Also I understand the problem is not inside Django. The problem inside gettext package or the way how Django use it.

comment:5 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

Accepting on the basis someone has reproduced the issue on Ubuntu 10.10. Open to any suggestions on whether this is a local configuration issue, an Ubuntu packaging stuff up, or a Django usage problem.

comment:6 Changed 4 years ago by jezdez

Yeah, I was able to reproduce this myself, and I first thought it would be able to be fixed by changing from using "Perl" to "Python". Guess we need to limit the use of gettext to 0.17 for now.

comment:7 follow-up: Changed 4 years ago by claudep

And as jezdez told us on IRC, the middle-term solution would be to use a real Javascript parser (not available in xgettext) to extract strings from js files (like the one in Babel: http://svn.edgewall.org/repos/babel/trunk/babel/messages/jslexer.py).

comment:8 in reply to: ↑ 7 Changed 4 years ago by lrekucki

Replying to claudep:

And as jezdez told us on IRC, the middle-term solution would be to use a real Javascript parser (not available in xgettext) to extract strings from js files (like the one in Babel: http://svn.edgewall.org/repos/babel/trunk/babel/messages/jslexer.py).

+Inf on using a real lexer/parser. See #15495 for another weird bug.

comment:9 Changed 4 years ago by nedbatchelder

  • Owner changed from nobody to nedbatchelder
  • Severity set to Normal
  • Status changed from reopened to new
  • Type set to Uncategorized

comment:10 Changed 4 years ago by nedbatchelder

  • Type changed from Uncategorized to Bug

comment:11 Changed 4 years ago by nedbatchelder

  • Cc ned@… added
  • Has patch set

See the patches on #7704 for a fix.

comment:12 Changed 4 years ago by jacob

  • Easy pickings unset

See also #15832 (which covers switching to Babel).

comment:13 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new 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