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

callable translation strings

This commit is contained in:
Samuel Štancl 2021-03-16 20:09:29 +01:00
parent 9948e4fd0f
commit 745513f251
3 changed files with 59 additions and 0 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Lean\Gloss;
use Countable;
use Illuminate\Support\Arr;
use Illuminate\Translation\Translator;
class GlossTranslator extends Translator
@ -217,4 +218,23 @@ class GlossTranslator extends Translator
$this->getSelector()->choose($line, $number, $locale), $replace
);
}
protected function getLine($namespace, $group, $locale, $item, array $replace)
{
$this->load($namespace, $group, $locale);
$line = Arr::get($this->loaded[$namespace][$group][$locale], $item);
if (is_string($line)) {
return $this->makeReplacements($line, $replace);
} else if (is_callable($line)) {
return app()->call($line, $replace);
} elseif (is_array($line) && count($line) > 0) {
foreach ($line as $key => $value) {
$line[$key] = $this->makeReplacements($value, $replace);
}
return $line;
}
}
}