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 /

Extending translatable


Reply


3 Posts   1082 Views

Avatar
Howard

Community Member, 215 Posts

18 May 2009 at 10:14pm

I am currently working on a site that requires translation and was hoping that when I added a translation to a page that has a image gallery attached or files associated with it then then these would remain associated with the translated page. i.e. if there is a page with 100 images in a gallery with a blurb above it then ideally i would just have to add a translation and not recreate the gallery.

How difficult would it be to add this customisation to translatable? Any points in the right direction?

Thanks,
Howard

Avatar
Ingo

Forum Moderator, 801 Posts

24 May 2009 at 6:37pm

We currently don't have support for excluding certain columns from being translated in the new datamodel. This includes columns like foreign keys to the image table. One way to work around this is to overload the getters and setters to query the original page instead.

[code php]
class MyPage extends Page {
   static $has_one = array('Image'=>'Image');
   
   function getImageID() {
      $original = $this->getTranslation(Translatable::default_locale());
      return ($original) ? $original->ImageID : null;
   }
   
   function setImageID($val) {
      $original = $this->getTranslation(Translatable::default_locale());
      if($original) {
         $original->ImageID : $val;
         $original->write();
      }
   }
}

I guess its in the "its not pretty, but it works" category... Caution, this code hasn't been tested in any way.

Avatar
Howard

Community Member, 215 Posts

24 May 2009 at 10:06pm

Hi Ingo,

Thanks for that, I figured, since I'm only adding one language, that i would use an alternative method. So i created additional title and content fields on the page class then select them using the URL - based on the idea used here [url]http://doc.silverstripe.com/doku.php?id=recipes:multilingual_content[/url]