T
T
Turganbay S2020-04-22 08:21:36
symfony
Turganbay S, 2020-04-22 08:21:36

Is there a Translatable Behavior for Doctrine that stores translations in json type?

The last time I used Doctrine was a couple of years ago. To translate entity fields, I used StofDoctrineExtensionsBundle where there is a separate table in the database for storing translations, or according to the translation table for each entity, and then they were joined. With the advent of support for JSON fields in MySql >=5.7.8 natively, it became possible to store translations in one column:

The name column in the database can now have the content:
{"ru": "Test", "en": "Test"}

and now the content will be pulled out with the key ru or en depending on the current locale, or saved under the correct key in the database when submitting the form with the value name=Test2&... , and the translation is elementary and simple.

Is there a Translatable Behavior for Doctrine that stores translations in json type?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2020-04-22
@Maksclub

According to the specified link, the author himself threw a solution with ValueObject, regardless of whether there is JSON support in the DBMS or not.
If you want to inject some behavior from the framework into this type, then you can do it like this:
get Type and add behavior to it in Kernel::boot (), for example, this is done here:
https://github.com/dunglas/doctrine -json-odm/blob/...
By the way, you can take the specified bundle as a whole, then all your work will come down to the fact that you just need to write a normalizer / denormalizer for your ValueObject

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question