diff --git a/framework/core/src/Api/Serializer/GroupSerializer.php b/framework/core/src/Api/Serializer/GroupSerializer.php index 285954554..99e0f0434 100644 --- a/framework/core/src/Api/Serializer/GroupSerializer.php +++ b/framework/core/src/Api/Serializer/GroupSerializer.php @@ -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; + } } diff --git a/framework/core/src/Core/Group.php b/framework/core/src/Core/Group.php index 213feb0f8..f49cb6efb 100755 --- a/framework/core/src/Core/Group.php +++ b/framework/core/src/Core/Group.php @@ -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;