Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29175 closed Cleanup/optimization (fixed)

makemessages doesn't parse ES6 template strings

Reported by: Artem Skoretskiy Owned by: nobody
Component: Documentation Version: 2.0
Severity: Normal Keywords:
Cc: Artem Skoretskiy Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ECMAScript 6 introduced template strings, that are easy to use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

But Django 2.0.2 does not recognize it when it tries to extract translations into PO file. It also gives you a warning in some cases.

Demo:

# main.js

let header = `${_("Header")}`;

const get_url = id => `/my_user/${id}/`;

let header_old = _("Header old");

Run:

./manage.py makemessages -d djangojs -a

PO file would contain only "Header old".

This is a synthetic example, you could see real-life file attached. It would generate following warnings:

api.js:90: warning: unterminated string
api.js:139: warning: RegExp literal terminated too early

As far as I get, it ignores back-ticks and treats content as regular expression here.

Attachments (2)

api.js (3.6 KB ) - added by Artem Skoretskiy 6 years ago.
Sample ES6 file that raises a warning
29174.diff (823 bytes ) - added by Claude Paroz 6 years ago.
Tentative doc patch

Download all attachments as: .zip

Change History (12)

by Artem Skoretskiy, 6 years ago

Attachment: api.js added

Sample ES6 file that raises a warning

comment:1 by Artem Skoretskiy, 6 years ago

Cc: Artem Skoretskiy added
Component: UncategorizedInternationalization
Type: UncategorizedBug

comment:2 by Tim Graham, 6 years ago

Isn't this an xgettext issue rather than something Django can solve?

comment:3 by Claude Paroz, 6 years ago

Component: InternationalizationDocumentation
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Same as #29174, I even found the gettext bug report: https://savannah.gnu.org/bugs/?50920

by Claude Paroz, 6 years ago

Attachment: 29174.diff added

Tentative doc patch

comment:4 by Claude Paroz, 6 years ago

Has patch: set

Draft patch attached for resolving both #29175 and #29174.

comment:5 by Tim Graham, 6 years ago

That looks okay. I create a PR. One comment there.

comment:6 by Tim Graham, 6 years ago

Summary: makemessages does parse ES6 template stringsmakemessages doesn't parse ES6 template strings

comment:7 by Carlton Gibson <carlton.gibson@…>, 6 years ago

Resolution: fixed
Status: newclosed

In c3437f73:

Fixed #29174, #29175 -- Doc'd that f-strings and JavaScript template strings can't be translated.

comment:8 by Carlton Gibson <carlton.gibson@…>, 6 years ago

In 8b4798c:

[1.11.x] Fixed #29174, #29175 -- Doc'd that f-strings and JavaScript template strings can't be translated.

Backport of c3437f734d03d93f798151f712064394652cabed from master

comment:9 by Carlton Gibson <carlton.gibson@…>, 6 years ago

In 0d2ec8d:

[2.0.x] Fixed #29174, #29175 -- Doc'd that f-strings and JavaScript template strings can't be translated.

Backport of c3437f734d03d93f798151f712064394652cabed from master

comment:10 by Carlton Gibson <carlton.gibson@…>, 6 years ago

In a5d1fe5:

Revert "[1.11.x] Fixed #29174, #29175 -- Doc'd that f-strings and JavaScript template strings can't be translated."

This reverts commit 8b4798c8d31b3cd9faab4caf11fca000b07f0181.

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