2

I am using Poedit's "Update from code" function to extract strings from my javascript code. The issue is that I use ES6 template strings in my code, like so:

const myVariable = 5;
const myString = `My variable value is: ${variable}`

This causes the following error to appear when I extract the string for translation:

warning: RegExp literal terminated too early

Some research told me that this is due to a bug with gettext.

Is there a way for me to still use Poedit with template strings or should I give up on the software?

Ryan Pergent
  • 4,432
  • 3
  • 36
  • 78

2 Answers2

0

You shouldn't give up on Poedit, which isn't even the culprit — GNU gettext is. What you should do is to always make sure you're using the latest version of any software you encounter any issues in; chances are your issue was already fixed since you installed your version.

GNU gettext introduced support for template literals in version 0.20. Poedit updated its bundled copy of GNU gettext to 0.20 in version 2.2.4 in September 2019.

EDIT: Here's a demonstration that current gettext works with the minimal sensible (i.e. with something to extract) code based on your snippet:

$ cat test.js
const myVariable = 5;
const myString = `My variable value is: ${variable}`
_('translatable string');

$ xgettext -o- test.js
# 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: 2020-03-01 10:44+0100\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"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: test.js:3
msgid "translatable string"
msgstr ""

$
Václav Slavík
  • 6,445
  • 2
  • 28
  • 25
  • That is indeed the first thing I did. The issue happens with the latest version of Poedit (2.3). I also have gettext version 0.20.1. – Ryan Pergent Feb 29 '20 at 16:37
  • @RyanPergent I don't know what to tell you except what should be obvious second nature to developers like you: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html ; perhaps reconsider your assumption (unverifiable with just some two out-of-context lines) that your issues have anything to do with template literals. – Václav Slavík Feb 29 '20 at 17:24
0

Figured it out. It turns out that the error was not caused by the template literals, but by the usage of JSX.

The app is a React app and writing something like

function MyComponent() {
    return <Comp></Comp>
}

Will trigger the warning, while this won't:

function MyComponent() {
    return (<Comp></Comp>)
}

In general, using JSX anywhere in my code without surrounding it with parenthesis seems to cause the issue.

Ryan Pergent
  • 4,432
  • 3
  • 36
  • 78