Opened 22 months ago

Closed 20 months ago

Last modified 20 months 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 22 months ago.
Sample ES6 file that raises a warning
29174.diff (823 bytes) - added by Claude Paroz 20 months ago.
Tentative doc patch

Download all attachments as: .zip

Change History (12)

Changed 22 months ago by Artem Skoretskiy

Attachment: api.js added

Sample ES6 file that raises a warning

comment:1 Changed 22 months ago by Artem Skoretskiy

Cc: Artem Skoretskiy added
Component: UncategorizedInternationalization
Type: UncategorizedBug

comment:2 Changed 21 months ago by Tim Graham

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

comment:3 Changed 21 months ago by Claude Paroz

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

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

Changed 20 months ago by Claude Paroz

Attachment: 29174.diff added

Tentative doc patch

comment:4 Changed 20 months ago by Claude Paroz

Has patch: set

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

comment:5 Changed 20 months ago by Tim Graham

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

comment:6 Changed 20 months ago by Tim Graham

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

comment:7 Changed 20 months ago by Carlton Gibson <carlton.gibson@…>

Resolution: fixed
Status: newclosed

In c3437f73:

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

comment:8 Changed 20 months ago by Carlton Gibson <carlton.gibson@…>

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 Changed 20 months ago by Carlton Gibson <carlton.gibson@…>

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 Changed 20 months ago by Carlton Gibson <carlton.gibson@…>

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