Skip to content

Commit eeb7356

Browse files
authored
Merge pull request #3 from derikb/issue-2
fix(Translation): Objects in context caused error
2 parents 4ec324c + e179d08 commit eeb7356

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/jblond/TwigTrans/Translation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,18 @@ public static function transGetText(string $value, array $context): string
4343
*/
4444
private static function replaceContext(string $string, array $context): string
4545
{
46+
// Without the brackets there is no need to run the rest of this method.
47+
if (mb_strpos($string, '{{') === false) {
48+
return $string;
49+
}
4650
foreach ($context as $key => $value) {
4751
if (is_array($value)) {
4852
return self::replaceContext($string, $value);
4953
}
54+
// Ignore objects, since only simple variables can be used
55+
if (is_object($value)) {
56+
continue;
57+
}
5058
$string = str_replace('{{ ' . $key . ' }}', $value, $string);
5159
}
5260
return $string;

0 commit comments

Comments
 (0)