php-gettext / Twig-Scanner

Twig code scanner for gettext
GNU General Public License v3.0
4 stars 2 forks source link

Embed tag not supported #5

Closed tehbeard closed 3 years ago

tehbeard commented 3 years ago

Ran in to this when trying to dump string translations from twig templates. Functions within embed tags aren't scanned.

embed-bug.twig

<div class="embed-wrapper">
<h2>{{ p__("500embed", "string outside of embed") }}</h2>
{% embed 'embed.twig' %}
    {% block main %}
        <h2>{{ p__("500embed", "Server Error") }}</h2>
        <p>...Rest of content cut for bug report...</p>
    {% endblock %}
{% endembed %}
</div>

embed.twig

<div class="mega-embed">
        {% block main %}
        {% endblock %}
</div>

extends works fine

extends-test.twig

{% extends 'embed.twig' %}
    {% block main %}
        <h2>{{ p__("500extends", "Server Error") }}</h2>
        <p>...Rest of content cut for bug report...</p>
    {% endblock %}

There might need to be special handling for it's Node class. I'll give it a look and see if I can make a PR to fix it. No real rush on it right now.

oscarotero commented 3 years ago

Thanks for reporting this. Your PR is appreciated

drzraf commented 3 years ago

Same. The patch sounds sane & logical. (Updated tests would be superb) :)