mirror of
https://github.com/flarum/framework.git
synced 2024-12-12 06:03:39 +08:00
parent
a74c4ebd71
commit
1dd847bd36
|
@ -10,9 +10,9 @@
|
|||
|
||||
namespace Flarum\Api\Serializer;
|
||||
|
||||
use Flarum\Api\Serializer\AbstractSerializer;
|
||||
use Flarum\Core\Group;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class GroupSerializer extends AbstractSerializer
|
||||
{
|
||||
|
@ -21,6 +21,19 @@ class GroupSerializer extends AbstractSerializer
|
|||
*/
|
||||
protected $type = 'groups';
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @param TranslatorInterface $translator
|
||||
*/
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@ -35,8 +48,8 @@ class GroupSerializer extends AbstractSerializer
|
|||
}
|
||||
|
||||
return [
|
||||
'nameSingular' => $group->name_singular,
|
||||
'namePlural' => $group->name_plural,
|
||||
'nameSingular' => $this->translateGroupName($group->name_singular),
|
||||
'namePlural' => $this->translateGroupName($group->name_plural),
|
||||
'color' => $group->color,
|
||||
'icon' => $group->icon,
|
||||
];
|
||||
|
@ -49,4 +62,19 @@ class GroupSerializer extends AbstractSerializer
|
|||
{
|
||||
return $this->hasMany('Flarum\Api\Serializers\PermissionSerializer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
private function translateGroupName($name)
|
||||
{
|
||||
$translation = $this->translator->trans('core.group.'.strtolower($name));
|
||||
|
||||
if ($translation !== $name) {
|
||||
return $translation;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
namespace Flarum\Core;
|
||||
|
||||
use Flarum\Core\Support\EventGeneratorTrait;
|
||||
use Flarum\Core\Support\Locked;
|
||||
use Flarum\Core\Support\ScopeVisibilityTrait;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Event\GroupWasCreated;
|
||||
|
|
Loading…
Reference in New Issue
Block a user