Translation Groups - what are they?

Translationgroups

When a DataObject is made translatable, after a /dev/build/?flush=1, SilverStripe will create a new TranslationGroup table in the database for it, that will link the different translations of one DataObject together. In each case one translation will be the master and all others will be linked to it. So if you make the siteTree Translatable:

Object::add_extension('SiteTree', 'Translatable');

SilverStripe will create new tables called SiteTree_TranslationGroups and SiteTree_Live_TranslationGroups, that look something like this:

ID OriginalID TranslationGroupID
1 1 1
2 18 1
3 4 4
2 24 4

This table links translated pages by placing them in the same translation group. In this example the pages with ID 1 and 18 belong to the same translationgroup (1) where page 1 is the master, lending its ID to the 'group'. Pages 4 and 24 again are translations of the same page, where page 4 is the master. These are some functions that can be called on a Translatable object:

getTranslationGroup()
Will return the ID (number) of the translationgroup the current object belongs to, use to find the master page...

addTranslationGroup($originalID, $overwrite = false)
will add a new record for the current object to a translationgroup. can be used to setting it up as a translation of some master object

removeTranslationGroup()
will remove the record for the current object from the translationgroup - ie the record where the OriginalID equals $this->ID. If this is the group's Master, this will probably leave the other translations in the group, so they will be linked but maserless. Handle with care I suppose...

getTranslatedLocales()
will get you an array of locales (sorted alfabeticale) for which a translation exists of the current object.

getTranslations($locale = null, $stage = null)
will get you a DataObjectSet of all translations for the current object, except the current object itself. If a locale is provided, it will only query for that special locale. If versioned is enabled for the object, you can provide a stage as well (Live, Stage); Unfortunately you cannot influence the order in which the translations are retreived.

Comments

Het versturen van reacties is uitgeschakeld.

RSS feed voor reacties op deze pagina