1

It all started with some efforts to localize a website. I was using Twig along with its I18n extension.

$extensions[] = new Twig_Extensions_Extension_I18n();

foreach ($extensions as $extension) {
  $twig->addExtension($extension);
}

I often want to re-use certain strings across different pages, but split the text domains into different files for better organization. It doesn't seem like Twig can pull from a specific text domain on its own, but when I google around, the Symfony version of the Twig i18n extension can do this.

Therein lies my confusion. I constantly find documentation for the Symfony version, but I seem to have a barebones version instead. To make matters more confusing, it seems Twig was produced by Symfony yet mine doesn't have all that fun stuff. I've run into other similar situations where functions I could really use were apparently only available when running within the Symfony framework.

Can anyone explain what's going on here? Can I switch to using the more capable Symfony twig extensions instead, perhaps? I feel quite confused about the whole thing.

Austin Burk
  • 930
  • 4
  • 15
  • 33
  • 2
    It can certainly be confusing. Symfony is a basic Request/Response framework. The framework uses what it calls bundles (aka modules) to integrate other libraries such as Twig. Hence it has a TwigBundle. But Symfony also has what it calls bridges which can provide extra functionality to the library but can be used outside of the framework. So TwigBridge. But wait there is more. Twig itself has another bundle called TwigExtraBundle. Like watching a soap opera. Just to make things interesting, both Twig and Symfony were designed by the same person. – Cerad Sep 16 '20 at 22:07
  • 2
    Bottom line: create a new symfony 5.1 project per the docs and then just trace whatever code you are interested in. And maybe you will be able to use it in your project. And perhaps off-topic but the class name Twig_Extensions_Extension_I18n implies you are using an old pre-namespace version of twig. Hopefully you can upgrade to something newer. Otherwise you will probably need to get a Symfony 2.8 app up and running. Which can be a challenge as it is no longer supported. – Cerad Sep 16 '20 at 22:08
  • Thanks for the insight and tips. I'm looking into it. – Austin Burk Sep 17 '20 at 17:20

0 Answers0