im learning Symfony 5 and was wondering if it is okay to put long strings / "messages" inside a controller (ex. addFlash message here), or there is a better way of storing them.
I think that my solution could become problematic when i try to translate my website to a different language.
class RegisterController extends AbstractController
{
public function index()
{
if ($form->isSubmitted() && $form->isValid()) {
...
$this->addFlash(
'info',
"Congratulations {$user}! You are now a part of growing <b>Symf</b> community! <br>
An activation link to <b>{$user->getEmail()}</b> was <u>not</u> sent because mailing is not implemented.
  <small>(...yet)</small>"
);
}
...
}
}
Tutorials and Symfony docs are doing it in controller but i know that might be just an example.
So my question is, is it a good practice to put long strings in variables/values in controller or is there a better way?
2
Answers
It’s probably a better practice to put those in a translation file. More information https://symfony.com/doc/current/translation.html
Technical alternatives
To provide alternatives to Marks suggestion of translation (which might not be useful now, but could become in the future), you could also use a method or const:
While it does remove noise from the actual logic, this is not great, a const this big feels clonky. What if you want to add more text? Maybe a link to a FAQ? Lets see how a private function does:
This is also not great, because the task of the controller is to control, not to manage texts. There are now two reasons to change this controller, which violates single responsibility.
But the (IMO) real solution:
Dont use toasts for this. Toasts are for short messages like "✓ Success" or "Confirmation mail sent". You’re now "abusing" this for something it’s not intended for and you can feel "resistance" in the implementation.
Just redirect the $user to a welcome page and use that to explain what is going on. You can add a little about a spambox check, or maybe some image to set the vibe.