bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gettext] [bug #50920] support Javascript template strings in xgette


From: Marco Trevisan
Subject: [bug-gettext] [bug #50920] support Javascript template strings in xgettext
Date: Thu, 6 Sep 2018 22:21:50 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0

Follow-up Comment #9, bug #50920 (project gettext):

While I agree that supporting template strings with placeholder is wrong, I
think is actually safe to support template strings when they only contain
normal text.

In any case, these strings should be properly parsed, and we should not ignore
them in case they contain a mix of apices.

For example a code like this:

# xgettext --language=javascript -o - --extract-all /tmp/test.js
let str = `that's a valid string. ` + _('This too');


A part of warn, it generates something like:


#: /tmp/test.js:1
msgid "s a valid string. ` + _("
msgstr ""

#: /tmp/test.js:1
msgid ");"
msgstr ""



Attached here, two patches that fix this.
The 1st one, just add support for the backtick (`) strings, while the second
one, discards them when they use javascript placeholders (so basically if
there's a "${" inside; and that's enough to respect the JS syntax).

In case --extract-all is passed we warn about this misusage, however I'd love
to do this in all the cases a template string is passed to a gettext flag
(i.e., only if we do _(`${foo}`), and not if we've just a print(`${foo}`)
call).

I've tried to do that, but unfortunately there are some xgettext limitations
at core level that make this quite annoying to do only changing the javascript
parser.

Ideally, I'd like to have a function that is called once the messageid is
extracted, just before the format parsing, and that can be used to verify the
content of the string, to check if this is legal or not.
I've tried to get the same with a literalstring_parser, but that's not doable
because it doesn't handle nullified msgid's, and that's a too late stage.

Anyway, the two commits here should fix the main issue, in the mean time we
don't decide to have something with a nicer feedback.

(file #44949, file #44950)
    _______________________________________________________

Additional Item Attachment:

File name: 0001-javascript-add-support-for-ES6-template-strings.patch Size:4
KB
File name: 0002-javascript-do-not-translate-template-strings-wit-pla.patch
Size:6 KB


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?50920>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]