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

admin

Administrator
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="http://twig.sensiolabs.org/" rel="nofollow noreferrer">twig template engine</a> in my PHP application. I am using the latest version of <a href="http://www.poedit.net/" 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="http://plugins.svn.wordpress.org/background-manager/trunk/vendor/pf4wp/TRANSLATE.md" rel="nofollow noreferrer">instructions</a>.

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

Code:
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:

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

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

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

However, if I click
Code:
OK
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="https://github.com/umpirsky/Twig-Gettext-Extractor" 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:

<ul>
<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
Code:
{{ t('some string') }}
</li>
<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>
</ul>

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.