Gettext throws "warning: unterminated string" when parsing twig template files


Staff member
This problem has been bothering me for a while, but I would like to fix it once and for all.

I am using the <a href="" rel="nofollow noreferrer">twig template engine</a> in my PHP application. I am using the latest version of <a href="" rel="nofollow noreferrer">Poedit</a> (which uses xgettext 0.18.1) to parse my files for translation strings.

I have set up Poedit to work with twig using these <a href="" rel="nofollow noreferrer">instructions</a>.

Everything works well, but the problem is that when I update my Poedit catalogue, I get errors like this:

1:24:45 PM: somefile.twig:5: warning: unterminated string
1:24:45 PM: somefile.twig:10: warning: unterminated string

This is the dialog:

<img src=" " alt="enter image description here">

And this is the file in question:

{% extends somevar ? 'one.twig' : 'two.twig' %}

{% block blah %}
Blah blah
{% endblock %}

{% block blah2%}
&lt;div id="some-id" class="some-class"&gt;
some content
{% endblock %}

However, if I click
in the error dialog, everything seems to be fine and the strings from the twig template are then loaded into the catalogue.

I know there is a <a href="" rel="nofollow noreferrer">gettext-extractor</a> for twig that has been released recently to pick out the translation strings. However, there are some possible issues:

<li>I am not using the symfony 2 framework and am not using the intl extension for twig (we have built our own to suit our purposes).</li>
<li>We use a different character for our gettext strings
{{ t('some string') }}
<li>We would prefer not to have to introduce more external dependencies unless we really have too, otherwise someone trying to get the strings would need to set up twig and the gettext extractor.</li>

Is there a flag I can pass to xgettext to solve this problem? The parsing works fine. I just prefer that the error to not be thrown by gettext.