Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Extending translatable

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 954 Views
  • Howard
    Avatar
    Community Member
    215 Posts

    Extending translatable Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Extending translatable Link to this post

    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.

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Extending translatable Link to this post

    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 http://doc.silverstripe.com/doku.php?id=recipes:multilingual_content

    954 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.