0
votes

Using ZfcTwig for ZF2 and twig-gettext-extractor, I still cannot extract messages for translation from twig-files by poedit. I works if I used the formal twig keyword for translation {% trans(MY_TEXT) %} but not for the in-built view helper translate. {{ translate(MY_Text) }} does the translation but poedit is just ignoring it. For new twig files, I want as usual let poedit do the job.... Any ideas for a solution?

2

2 Answers

1
votes

Maybe you need to edit catalog properties keywords to be visible for translations. Open PoEdit, go to Catalog -> Properties -> Sources keywords and add another keyword "translate". Here I attach an screenshot. enter image description here

0
votes

The problem is that the extractor you are using is just caching the files and running them through xgettext to extract calls to trans/translate/_/.. (keywords as suggested by Conti. Alas ZfcTwig will crosscompile calls to ZF2 plugins into plugin('translate')->__invoke('Your Text to be translated'). You could of course now add __invoke as a new keyword in poedit or whatever you favorite gui for using xgettext is, but it will now find all calls to all view helpers not just those to translate.

I ran into this problem myself and I have not come up with a satisfying solution. The Twig Gettext Extension looks promising in terms of writing your own customized POT-File generator that will handle translate and translatePlural view helper calls. Using the extension as is will bypass all translation from ZF2. ZF2 parses .mo files into an internal structure rather than using the php-gettext mod.

All in all I gave up on automated po(t) file generation for ZF2+ZfcTwig for now and am back to phpArray.