Titeufggg
Titeufggg

Reputation: 21

User current Locale inside entity OR trait

How can we access to current user local inside entity or Trait ?

namespace App\Entity;


class Activities
{
    use Translation;

   public $locale;

    public function __construct(**PUT User locale**)
    {
        $this->locale = **PUT User locale**
    }

}

Upvotes: 0

Views: 239

Answers (1)

Vincent PHILIPPE
Vincent PHILIPPE

Reputation: 1191

You can't do that, because the locale is stored into the Request object which should'nt be accessed from an entity.

So if you really need that locale, you should pass it as an argument.

I suggest you to look around the Doctrine extension documentation for translating entities.

You'll see that it's better than just passing the user locale each time. In fact, it is using event listener to pass the locale to the Translation component.

Upvotes: 0

Related Questions