I
I
Igor2020-01-20 22:04:10
symfony
Igor, 2020-01-20 22:04:10

How to extract the data of the desired locale?

I managed to implement a record in the database, data in different languages.
Based on the following source.
Writing to the database is as follows

$food = new Category;
$food->setName('Кофе');
$food->addTranslation(new CategoryTranslation('en', 'title', 'Coffee'));
$food->addTranslation(new CategoryTranslation('cn', 'title', '咖啡'));

$food->addTranslation(new CategoryTranslation('en', 'description', 'Description in English'));
$food->addTranslation(new CategoryTranslation('cn', 'description', '英文说明'));

$manager->persist($food);
$manager->flush();

return $message->success("Категория добавлена!");

As a result, I got something
5e25f9346de6c623266890.png
5e25f93e4acf3133656279.png
. I guess everything was exactly as it was intended.
Attention to the question, how to correctly get the data and fill in the Entity in accordance with the selected locale?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question