Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 94081fc

Browse files
committed
extend translate for parameters
1 parent 31353b9 commit 94081fc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Twig/TwigExtensions.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ protected function extendForTranslator() : void
3333
$filter = new \Twig_SimpleFunction(
3434
'translate',
3535
function (
36-
$string
36+
$string, ...$findAndReplace
3737
) use ($dictionary) {
3838
if (array_key_exists($string, $dictionary)) {
39-
return $dictionary[$string];
39+
$string = $dictionary[$string];
40+
}
41+
if (! empty($findAndReplace)) {
42+
foreach ($findAndReplace[0] as $find => $replace) {
43+
$string = str_replace('{{'.$find.'}}', $replace, $string);
44+
}
4045
}
4146
return $string;
4247
},

0 commit comments

Comments
 (0)