Update __() function

This commit is contained in:
Visman 2021-11-29 18:54:40 +07:00
parent 7276fb8bc5
commit f8d12617aa

View file

@ -45,23 +45,23 @@ function __(/* string|arrray */ $arg): string
} }
if (\is_array($arg)) { if (\is_array($arg)) {
$tr = $lang->get(\reset($arg)); $str = \array_shift($arg);
$args = \array_slice($arg, 1); $tr = $lang->get($str);
if (null === $tr) { if (null === $tr) {
$tr = e(\reset($arg)); $tr = e($str);
} elseif (\is_array($tr)) { } elseif (\is_array($tr)) {
$tr = $lang->getForm($tr, \reset($args)); $num = \array_shift($arg);
$args = \array_slice($args, 1); $tr = $lang->getForm($tr, $num);
} }
if (empty($args)) { if (empty($arg)) {
return $tr; return $tr;
} elseif (\is_array(\reset($args))) { } elseif (\is_array(\reset($arg))) {
return \strtr($tr, \array_map('\\ForkBB\\e', \reset($args))); return \strtr($tr, \array_map('\\ForkBB\\e', \reset($arg)));
} else { } else {
$args = \array_map('\\ForkBB\\e', $args); $arg = \array_map('\\ForkBB\\e', $arg);
return \sprintf($tr, ...$args); return \sprintf($tr, ...$arg);
} }
} else { } else {
return $lang->get($arg) ?? e($arg); return $lang->get($arg) ?? e($arg);