Hi,
I wanted to share with everyone something I've created to be an alternative to the Translatable paradigm. It's one thing that bugs me with silverstripe, I don't like to have duplicated entries in my database or instead of translatable, using fields like myfield_en, myfield_fr is not very flexible. So, I got the idea to work on a dataobjectdecorator that is going to allow to make some fields localizable, while keeping only one "master" record. To achieve this, I simply create a table to store the localized fields called mytable_locale and use one row with the parentid and the locale + the localized fields.
The thing I like with this, is that I only make one query to get my translated dataobject every time (because i simply do a left join to get my localized fields), that I can rely on one single id as the reference, without having to go through a translationgroup table. As an extra bonus, it is super simple to edit in the admin because I don't need to have a special modeladmin or switch language or anything like that. I just create a tabset, with one tab for each locale, with the translated fields. Super easy.
It's still a bit rough right now and could surely be improved, but you can see a working example
http://www.sspaste.com/paste/show/4ec261c450c59
To use it, simply :
Object::add_extension('MyDataObject', 'Localizable');
Declare this property on the dataobject :
public static $localizableFields = array(
'name' => 'type'
);
And if you want to access transparently to your localized field, simply overload the __get method (haven't found a way to do this in the dataobject decorator)
function __get($fieldName) {
if($this->hasLocalization($fieldName) && Localizable::$automaticLocalization) {
return $this->localize($fieldName);
}
return parent::__get($fieldName);
}
What do you think of this approach ? any comments, suggestions?