This problem has been bothering me for a while, but I would like to fix it once and for all.
I am using the twig template engine in my PHP application. I am using the latest version of Poedit (which uses xgettext 0.18.1) to parse my files for translation strings.
I have set up Poedit to work with twig using these instructions.
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:
And this is the file in question:
{% extends somevar ? 'one.twig' : 'two.twig' %}
{% block blah %}
Blah blah
{% endblock %}
{% block blah2%}
<div id="some-id" class="some-class">
some content
</div>
{% endblock %}
However, if I click 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 gettext-extractor for twig that has been released recently to pick out the translation strings. However, there are some possible issues:
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).
We use a different character for our gettext strings {{ t('some string') }}
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.
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.
So I continued using that workflow for a few days and found the following problem:
If I have a resource bundle key like so: <a href="#" title="{{ t('somekey') }}">Test</a>
, the settings I was using previously would not pick up the key.
Since I already had a small PHP script in the background to monitor and compile my assets using Assetic, I simply added a few more lines for the twig templates to be compiled into PHP files (http://twig.sensiolabs.org/doc/extensions/i18n.html#extracting-template-strings).
I then remove the Twig parser from POEdit and now, all the template strings are just parsed from PHP files, which works great!
While this solution works, I would still like to find a way to get POEdit and gettext to parse twig files natively. However, if anyone is looking for a solution, this one should work quite well in the meantime.