JBlond / twig-trans

Twig 3 translation extension

Home Page:https://github.com/JBlond/twig-trans

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Objects in $context cause error

derikb opened this issue · comments

Was hoping to use this plugin with twig 3 since the symfony translation thing does not seem to work with xgettext, but came upon a significant issue.

In Translation::replaceContext the code does not account for objects. So if my context has something like:

'reply' => (object) [
  'id' => 123,
  'body' => 'some text'
]

PHP errors out when you get to the str_replace on line 50.

Also might save considerable effort if the string were first checked for {{ to see if any vars even need replacing.

I'm going to fork and code a fix. Maybe you'll be interested in a PR then if this project is still active.