1
0
Fork 0
mirror of https://github.com/archtechx/gloss.git synced 2025-12-12 11:14:04 +00:00

support closures inside arrays

This commit is contained in:
Samuel Štancl 2021-05-04 16:12:02 +02:00
parent d40e868b13
commit 7c509ed137

View file

@ -229,20 +229,27 @@ class GlossTranslator extends Translator
if (is_string($line) || is_callable($line)) { // Changed
return $this->makeReplacements($line, $replace);
} elseif (is_array($line) && count($line) > 0) {
foreach ($line as $key => $value) {
if (! is_callable($value)) {
$value = $this->makeReplacements($value, $replace);
}
$line[$key] = $value;
}
return $line;
return $this->makeReplacementsInArray($line, $replace);
}
return null;
}
protected function makeReplacementsInArray(array $lines, array $replace): array
{
foreach ($lines as $key => $value) {
if (is_array($value)) {
$value = $this->makeReplacementsInArray($value, $replace);
} else {
$value = $this->makeReplacements($value, $replace);
}
$lines[$key] = $value;
}
return $lines;
}
/**
* @param string|callable $line
* @param array $replace