4

In the Translatable behaviour of the Gedmo Doctrine Extensions, it has instructions on "Personal Translations". Could someone clarify what personal translations are?

1 Answer 1

6

tl;dr

Personal translations are used when you want to handle the translation entity (with it's own table by yourself) instead of the default behaviour, by using a single table for all translations.


By using the default behaviour, you get a single table called ext_translations which holds all of your translation data. I'll give you an example based on the documentation of DoctrineExtensions.

Let's say we create an Article entity with 2 translatable fields - title and content. That would mean that we should have the following table structure of articles:

+----+-------+---------+
| id | title | content |
+----+-------+---------+

Now, by default the TranslatableListener sets en_us locale every time you create new entity, thus populating only articles table:

$article = new Article();
$article->setTitle('Title english');
$article->setContent('Content english');

Would lead to the following:

+----+---------------+-----------------+
| id |     title     |     content     |
+----+---------------+-----------------+
|  1 | Title english | Content english |
+----+---------------+-----------------+

By now, only articles get to be updated with new records, but when you want to translate those fields with different locale, our common table ext_translations get updated as well.

The table has the following structure:

+----+--------+---------------+---------+-------------+------------+
| id | locale | object_class  |  field  | foreign_key |  content   |
+----+--------+---------------+---------+-------------+------------+

So, what happens when we update our record with some new translations:

$article->setTitle('My title');
$article->setContent('My content');
$article->setTranslatableLocale('de_de');

When we persist our updated entity, we get the following structure in ext_translations:

+----+--------+---------------+---------+-------------+------------+
| id | locale | object_class  |  field  | foreign_key |  content   |
+----+--------+---------------+---------+-------------+------------+
|  1 | de_de  | Bundle\Entity | title   |           1 | My title   |
|  2 | de_de  | Bundle\Entity | content |           1 | My content |
+----+--------+---------------+---------+-------------+------------+

Now you know how the default behaviour works. It stores all of your translations (not just for single entity, all of them) in a single table.

But when you're using a personal translations you can store your (let's say for the sake of our example) Article translations to its own, separate table, article_translations.

If you are familiar with DoctrineExtensions provided by KnpLabs, then you've already seen what stands for PersonalTranslations. Link for their documentation about this subject can be found here.

Well hopes this can clarify things a bit for you. Let me know if you have more questions about this.

4
  • 5
    Hey, this is not quite right. You don't need to use "Personal translations " to achieve this behaviour. Personal translations are meant to be used when you want to actually control the persistence behaviour within an entity translations in form of an Array collection of translations. Now you can map the collection with a onetomany mapping to the corresponding entity translation class AND you can now control stuff like cascading etc. If you want to have just separate tables, you can Do this by creating an entity translation class for each entity as described in the docs Sep 1, 2015 at 20:41
  • Yes, in short - using 1-m is what basically the end result. What I've briefly shown here is the default behaviour with some explanation behind it. No sample mapping or anything like that.
    – Artamiel
    Sep 1, 2015 at 20:46
  • 1
    Ok, just wanted to point out that there are three possible translation ways with gedmo: default, a table for each or personal (includes table for each and extra stuff) Sep 1, 2015 at 20:47
  • 1
    (of course you can combine them how you want to, but these are the recommended ways) Sep 1, 2015 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.