Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Translate / Translatable and Dataobjects

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

Page: 1 2
Go to End
Author Topic: 5438 Views
  • derralf
    Avatar
    Community Member
    24 Posts

    Translate / Translatable and Dataobjects Link to this post

    Hi Community

    can anyone help me with Translatable and Dataobjects?

    I'm currently testing a multilanguage setup. Translatable works fine for my first test pages.
    I additionally have dataobjects (called GalleryImage) with has_one relations (image) and text fields (Title, description, and so on).
    i put "Object::add_extension('GalleryImage', 'Translatable');" in my config and the GalleryImage_translationgroups table was built.
    Now, how can i translate my data objects? where do i find or how can i add the nice "create new language" dropdown or something similar?

    Please Help....

    Thanks, Ralf

  • derralf
    Avatar
    Community Member
    24 Posts

    Re: Translate / Translatable and Dataobjects Link to this post

    ok, no answer
    and neither DOM nor CTF seem to like my translatable DataObjects very much...

    so i ended up doing following:
    - truned OFF Translatable for my DataObject
    - added following fields: 'Title_en_US' and 'Description_en_US' (my default locale is de_DE)
    - so i won't have to duplicate my gallery images for translation (like Translatable does in SiteTree) and have information for all languages in one Dataobject.

    in my GalleryImage.php i added a function like this:

    public function localeTitle() {
       if (Director::currentPage()->Locale != Translatable::default_locale()) {
          $functionName = 'Title_'.Director::currentPage()->Locale;
          $this->Title = $this->$functionName;
       }
       return $this->Title;
    }

    and similar for description so i can access the right (translated) title and description from my templates.

    in my GalleryPage.php i did something this:

    function translatedGalleryImages() {
       $Data = $this -> GalleryImages();
       // Get Dataobjects from Original-Languague-Page
       if ($this->Locale != Translatable::default_locale()) {
          $Data = $this->getTranslation(Translatable::default_locale()) -> GalleryImages();
       }
       return $Data;
    }

       

    so i can control the translated Dataobjects in the Template with <% translatedGalleryImages %>

    and in in function getCMSFields():

    ...
    $galeriemanager = new HasManyComplexTableField(... ctf config ....);
    ...
    if (Director::currentPage()->Locale == Translatable::default_locale()) {
       $fields->addFieldToTab('Root.Content.Galerie', $galeriemanager);
    } else {
       $fields->addFieldToTab('Root.Content.Galerie', new LiteralField('Gallery Message','<p>Galerie bitte in Standardsprache ('.Translatable::default_locale().') bearbeiten</p><p>Please edit your gallery in default language ('.Translatable::default_locale().')</p>'));
    }
    return $fields;
    ...

    maybe one can define the original language as fallback (Title/Description) or filter objects which have/haven't filled out fields for current displayed language...

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Translate / Translatable and Dataobjects Link to this post

    I'm having the same problem on my current project. How can I add a nice 'create new language' Button on my Customized DataObject in the ModelAdmin?

    derralfs solution is not practicable for my DataObject, as it would require do duplicate about 35 fields. Moreover it's not the way Translatable and DataObject was build for, is it?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Translate / Translatable and Dataobjects Link to this post

    I'm going to hit this wall soon... it is the one reason to keep all of your data in the sitetree and have it managed in the 'Create Translation' stuff. The most key items that are mostly content are going to return into the site tree for this reason.

    But there are still many items that cannot go there and I use ModelAdmin to manage their data.

    My plan is to take the items that need to be translated and move them into 'WebsiteDisplayData' (with a has_one locale) type object and then link them to the original dataobject with a has_many.... so....

    OriginalDataObject
    -Name*
    -Description*
    -OtherStuff

    *needs to be translated

    becomes...

    NewDataObject
    -has_many NewDataObjectWebsiteDisplayData
    -OtherStuff

    NewDataObjectWebsiteDisplayData
    -Name
    -Description
    -has_one Locale

    What do you think? Is there a better way?

    Another possibility (that might become a module as it is a more generic way of doing it..) could be to create something that you can select a dataobject and then create a translation of it's data where you can then select each field and enter your translation. This would store something like...

    class TranslatableDataObject
    {
       static $db = array(
          DataObjectID
          DataObjectClassName
          Locale
          Field
          Translation
       );
    }

    Then a function could be created like...

    function TranslateDataObject($doMyObject)

    ...that could look up the object id in the translation and then overwrite the fields that have a translation as specified above.

    Maybe this is a topic for the core dev list?

    Barry

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Translate / Translatable and Dataobjects Link to this post

    After reading this.... http://www.silverstripe.org/data-model-questions/show/293323#post293323

    It is clear that the option of has_many translations for my fields is not going to work because the popup HTMLField is not working with tinymce... anyone got this functionality working?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Translate / Translatable and Dataobjects Link to this post

    We've created a proof of concept ModelAdmin with Translatable a while ago: http://open.silverstripe.org/browser/modules/translatablemodeladmin/trunk

    It basically adds a language switcher to the ModelAdmin UI, and then hooks the language filtering into search results and adds it to new records. It doesn't take care of making a ComplexTableFIeld (or any relations edited through ModelAdmin) translatable, but should illustrate whats generally required to do this.

    Anybody keen to pick up this module and extend it? We could use:
    - List of existing translations (linked to translated edit form) on each record edit form
    - "Create translation" dropdown/button
    - Readonly fields of original language (that might already be in place through Translatable->updateCMSFIelds())

    In terms of getting CTF to support Translatable:
    - Add a language dropdown on the "add" popup
    - Limit listing based on $_GET['Locale'] (or TranslatableCTF->$locale really).
    - Links to existing translations in "edit" popup

    Any takers?

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Translate / Translatable and Dataobjects Link to this post

    Well here is a patch for 2.4.2 to enable some of the javascript.

    was...

    $('#myid').livequery('click', function() ...

    is now...

    jQuery('#myid').change(function() ...

    And yes that is very nice and can help very much - but there are quite a few things that will be need to make it "user" proof! It won't be for a couple of weeks because I have some other development from our software which I have promised to make open. But definitaly as I move forward this is a great start.

    Thanks!

    Attached Files
  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Translate / Translatable and Dataobjects Link to this post

    I've committed your patch in http://open.silverstripe.org/changeset/112300

    Looking forward to your contributions on this module - yeah, I think there's still a lot to do in terms of UI ;)

    5438 Views
Page: 1 2
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.