Skip to content

Commit

Permalink
Merge pull request #3 from derikb/issue-2
Browse files Browse the repository at this point in the history
fix(Translation): Objects in context caused error
  • Loading branch information
JBlond committed May 4, 2021
2 parents 4ec324c + e179d08 commit eeb7356
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/jblond/TwigTrans/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ public static function transGetText(string $value, array $context): string
*/
private static function replaceContext(string $string, array $context): string
{
// Without the brackets there is no need to run the rest of this method.
if (mb_strpos($string, '{{') === false) {
return $string;
}
foreach ($context as $key => $value) {
if (is_array($value)) {
return self::replaceContext($string, $value);
}
// Ignore objects, since only simple variables can be used
if (is_object($value)) {
continue;
}
$string = str_replace('{{ ' . $key . ' }}', $value, $string);
}
return $string;
Expand Down

0 comments on commit eeb7356

Please sign in to comment.