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

Commit

Permalink
extend translate for parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Mar 14, 2019
1 parent 31353b9 commit 94081fc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Twig/TwigExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ protected function extendForTranslator() : void
$filter = new \Twig_SimpleFunction(
'translate',
function (
$string
$string, ...$findAndReplace
) use ($dictionary) {
if (array_key_exists($string, $dictionary)) {
return $dictionary[$string];
$string = $dictionary[$string];
}
if (! empty($findAndReplace)) {
foreach ($findAndReplace[0] as $find => $replace) {
$string = str_replace('{{'.$find.'}}', $replace, $string);
}
}
return $string;
},
Expand Down

0 comments on commit 94081fc

Please sign in to comment.