Closed uran1980 closed 11 years ago
Hi.
If you look at twig-gettext-extractor#L41 you will see that there is a place where I registered some default extensions, and left place for new ones.
What you can do is copy this script to your bin folder for example cp vendor/bin/twig-gettext-extractor bin/twig-gettext-extractor
, and then customize it by adding something like:
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension());
and now use your bin/twig-gettext-extractor
with Poedit.
You can do same for every other extension, even for your custom extensions ;)
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension());
does not work. I try that, as AsseticExtension need AssetFactory:
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension(
new Assetic\Factory\AssetFactory($rootDir)
));
But recive Exeption:
An exception has been thrown during the compilation of a template ("There is no filter manager.") in "...\FrontendBundle\Resources\views\layout.html.twig".
at the moment I can't figure out how to add AsseticExtension throw $twig->addExtention()
method in a correct way...
@uran1980 Full trace would be nice to have, but as far as I can see, you are missing FilterManager
, you can set it with:
$assetFactory->setFilterManager(new Assetic\FilterManager);
Yes it work. Greate!!!
// setup filter manager
$filterManager = new Assetic\FilterManager();
$filterManager->set('cssrewrite', new Assetic\Filter\CssRewriteFilter());
// set other filters if needed...
// setup asset factory
$assetFactory = new Assetic\Factory\AssetFactory($rootDir);
$assetFactory->setFilterManager($filterManager);
// add extension
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension($assetFactory));
And now I am struggle with next final Exception:
2013-01-02 19:58:33] twig-gettext-extractor.log.INFO: Array
(
[method] => Twig\Gettext\Extractor::addTemplate
[line] => 67
[exeption] => Exception: The function "asset" does not exist in "...\FrontendBundle\Resources\views\Default\_includes\content.html.twig" at line 12
)
[] []
So now I need add to twig-gettext-extractor support for recognize asset function :) Thanks for advice :+1:
Can you please post "...\FrontendBundle\Resources\views\Default_includes\content.html.twig" at line 12?
Yes, it is a plain twig template:
Try to change:
// add extension
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension($assetFactory));
to
// add extension
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension($assetFactory), array('asset'));
I change to:
// add extension
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension(
$assetFactory,
array('asset')
));
But no result, same Exception as before:
[2013-01-02 21:14:55] twig-gettext-extractor.log.INFO: Array
(
[method] => Twig\Gettext\Extractor::addTemplate
[line] => 67
[exeption] => Exception: The function "asset" does not exist in "...\FrontendBundle\Resources\views\Default\_includes\content.html.twig" at line 12
)
[] []
I solve it finaly and that work pirfect :)
// setup filter manager
$filterManager = new Assetic\FilterManager();
$filterManager->set('cssrewrite', new Assetic\Filter\CssRewriteFilter());
// set other filters if needed...
// add functions
$twig->addFunction('asset', new Twig_SimpleFunction('asset', true));
// set other functions if needed...
// setup asset factory
$assetFactory = new Assetic\Factory\AssetFactory($rootDir);
$assetFactory->setFilterManager($filterManager);
// add extension
$twig->addExtension(new Assetic\Extension\Twig\AsseticExtension($assetFactory));
Now all my trans in all twig templates are processed by PoEdit.
Thanks again @umpirsky for your advice.
Great.
I think there must be a simpler way around :)
Hi, @umpirsky
When I use assetic bundle functionality in my twig templates I recive Exeptions in
Twig\Gettext\Extractor::addTemplate
method.When I use in twig template asset, for example:
Twig\Gettext\Extractor::addTemplate
method throws exception with message:When I use in twig template stylesheets, for example:
Twig\Gettext\Extractor::addTemplate
method throws exception with message:I partially solve this by adding try-catch statement to
Twig\Gettext\Extractor::addTemplate
method:Now problematic twig templates are skiped from processing, and translations in it are too (that is bad). I understend that root problem in twig engine. Any suggestions?
Thanks.