umpirsky / Twig-Gettext-Extractor

The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.
MIT License
113 stars 32 forks source link

Not working with TWIG ~1.24 #47

Open cheplv opened 8 years ago

cheplv commented 8 years ago

Due to changes of twig translations method in generated PHP templates - need to add correct keyword. Current translation string looks like: $this->env->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslator()->trans("Greeting.", array(), "messages");

I'v solved this with changing language parameter with keyword parameter. Command looks like: twig-gettext-extractor --sort-output --force-po -o messages.pot --keyword="trans" --files cat /tmp/tempfile

umpirsky commented 8 years ago

Thanks!

We should handle this. PRs are welcome. :)

cheplv commented 8 years ago

Added new PR.

cheplv commented 8 years ago

There was one more thing: transchoice function

drzraf commented 7 years ago

Wow! Great. Tested: it solved the issue for me. thx

drzraf commented 7 years ago

But note, that this construct does not seem to be recognized (not converted from Twig to PHP):

Submitted by %author_name% on %date%|trans({'%author_name%': author_name, '%date%': date})

drzraf commented 7 years ago

Also this fails too:

{% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %}

with

Twig_Error_Syntax: A message inside a trans tag must be a simple text

While it should not.

But this:

{% trans with {'%author_name%': author_name, '%date%': date} %}

works

cheplv commented 7 years ago

There was changes in twig relating translation, this cause me open this ticket :) More info: http://symfony.com/doc/current/translation.html Need to make investigation on this generated code: Submitted by %author_name% on %date%|trans({'%author_name%': author_name, '%date%': date})

umpirsky commented 7 years ago

Are you sure this is Twig specific and not Symfony specfic? Because you linked Symfony documentation.