G
G
gitdev2018-11-08 15:14:33
symfony
gitdev, 2018-11-08 15:14:33

How to translate text inside an entity in Symfony 4?

in the toString method, the text is returned, it needs to be localized. how to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Flying, 2018-11-09
@gitdev

Since entities, by definition, should be very lightweight objects, there are several possible solutions to consider here:

  • You can give the entity the ability to pull some known and accessible method from which it will receive a translator object, for example, it can be some StaticTranslatorProviderwith a static method getTranslator(). Overall, not a good idea, but it will work.
  • It is possible not to touch entities at all, but to request localization directly in the external code. In general, a bad option, but still possible
  • V
    Vadim, 2018-11-08
    @kylt_lichnosti

    I think you will find the answer here:
    https://symfony.com/doc/current/translation.html

    Didn't find what you were looking for?

    Ask your question

    Ask a Question

    731 491 924 answers to any question