JBlond/twig-trans

Bug: Objects in $context cause error

derikb opened this issue · 0 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.