Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Odd Translatable behavior


Reply


4 Posts   1383 Views

Avatar
ChrisBryer

Community Member, 95 Posts

13 February 2010 at 8:25am

Hi Everyone,
I have the following code in my _config file to make sitetree and dataobjects translatable:

Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('DOStaffMember', 'Translatable'); //Dataobject

Object::add_extension('DOEvent', 'Translatable'); //Dataobject
Object::add_extension('DOAudioVideoFile', 'Translatable'); //Dataobject
Object::add_extension('DOFolder', 'Translatable'); //Dataobject

Object::add_extension('DOPatent', 'Translatable'); //Dataobject
Object::add_extension('DOFrequentlyAskedQuestion', 'Translatable'); //Dataobject

//Restrict all locales to this list:
Translatable::set_allowed_locales(array(
      'en_US',
      'de_DE',
      'ja_JP'
   )
);

The problem that I am getting is that a 'Locale' column appears on my sitetree table (which is normal), but also on tables that have extended the Page class, like Homepage and Blog.

this is messing up some things like Blog archive where it uses a Natural Join in a DB::query() call. (the join finds 2 locale tables and returns nothing)

does anyone have any thoughts why these extra columns are being created? The site is using SS 2.3.3 or 2.3.4 (yes, i need to upgrade). I tried only decorating sitetree with Translatable, and removed the Decorators from the DataObjects, deleted the Locale tables from Homepage, but they are added once i do another dev/build/.

I'd love to hear any suggestions.

thanks,
-Chris

Avatar
ChrisBryer

Community Member, 95 Posts

16 February 2010 at 4:32am

I found out that a dataobjectdecorator that i am using on BlogEntry is causing the problem. something tells me that this is a bug between dataobjectdecorator and the Translatable extension. adding this decorator with this code causes the problems:

// BlogEntryDecorator.php
<?php

class BlogEntryDecorator extends DataObjectDecorator {
   function extraStatics() {
      return array(
         'db' => array(
            'PodcastContent' => 'HTMLText',
         )
      );
   }
   public function updateCMSFields(FieldSet &$fields) {
      $fields->addFieldToTab('Root.Content.EmbedCode', new TextAreaField('PodcastContent', 'Embed Code'));
   }
}
?>

//mysite/_config.php
<?php
//...
DataObject::add_extension('BlogEntry', 'BlogEntryDecorator');
//...

Avatar
Ingo

Forum Moderator, 801 Posts

21 February 2010 at 7:33pm

I've just tried your BlogEntryDecorator with the newest 2.3 and blog 0.2.1 - works as expected here, no duplicated Locale columns in the BlogEntry table. Sure you haven't added Translatable to BlogEntry at some point? Keep in mind that these columns won't be deleted automatically. Can you reproduce the problem on a fresh database?

Avatar
ChrisBryer

Community Member, 95 Posts

23 February 2010 at 4:19am

Hi Ingo,
Thanks for looking into this. i upgraded the site to 2.3.6 (was running 2.3.3) and deleted the locale columns from appropriate tables and everything works fine now. the reason why i hadnt upgraded the site to 2.3.6 was because i had to apply a [url=http://open.silverstripe.org/ticket/4199]patch #4199[/url] to make CTF's work in all locales. i know that you want to avoid session variables in the solution, and i'm curious if you have a recommended solution to fix that problem. it just makes upgrading a little harder on a multi-lingual website.

thanks again for looking into this! I really appreciate the help!
-Chris