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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Translatable custom data object?


Go to End
Reply


18 Posts   3576 Views

Avatar
spyrosk

Community Member, 16 Posts

20 December 2010 at 1:46pm

Hi! I'm new to Silverstripe and although I like it's approach very much, I'm a bit overwhelmed with all the information. Here is what I would like to do:
Create something like a portfolio page with links to categories/types of projects and other attributes, e.g. client, year of completion, start date etc.
Each project should have a few custom fields, like the ones mentioned above, and a few images that will be displayed on it's page. Some fields should be just custom text, but others should be selected from a drop-down list.
And here is the funny part, the site should support 2 to 3 different languages.. :(

Has anyone implemented anything like this in the past? Is it possible using SS, without having separate installations?
I don't seek a ready made solution, just a little guidance on how I should tackle this. I have already looked at modules like DOM, Uploadify etc, but I haven't found a solution regarding the multilingual and fields issue.
Thank you and sorry if I posted this in the wrong section.

Avatar
MarcusDalgren

Community Member, 288 Posts

21 December 2010 at 12:51am

Yes this is very doable!

Translatable is a part of the core so what you need to do is activate it in your _config.php file. Put this in the config

Object::add_extension('SiteTree', 'Translatable');

and then run dev/build?flush=all. After that you can use

Translatable::set_allowed_locales(array('sv_SE','en_US'));
Translatable::set_default_locale('sv_SE');

to setup the languages you want to use on your site and the default language for your site. The fields issue isn't really an issue, you can add any fields you like to your classes. If you've used WordPress then SilverStripe handles "custom fields" very differently.

If you haven't gone through the tutorials on doc.silverstripe.org then I recommend you start there. If you decide to do your portfolio and projects as page classes then this should get you pretty far.

Avatar
swaiba

Forum Moderator, 1799 Posts

21 December 2010 at 1:26am

Hi,

Just in case the above does not answer the "dataobject" part of the question, this may be of interest.... http://www.silverstripe.org/data-model-questions/show/8397#post293654

Avatar
spyrosk

Community Member, 16 Posts

24 December 2010 at 3:53am

Hello and thank you for your help, I really appreciate it! :)
I've gone through the tutorials/docs and I think I have my pages/dataObjects relationships planned out.
I would like to ask some more questions though because I'm still confused about this. I'll try to explain it with an example.
Let's say that my relationships are these:
Project hasOne ProjectCountry (1 to many)
Project hasMany ProjectTags (Many to many)
Project hasMany ProjectImages (Many to many)

Now, ProjectPage is, as the name suggests, extends the Page class. The question is should I implement the additional objects (ProjectCountry, ProjectTags) as sub-classes of Page or DataObject?
How will the translations work in each case?
Will I be able to make translations through the Translations tab in the case of the DataObject or not (so I must define them as Page extensions)?

Thank you again for your help!

Avatar
spyrosk

Community Member, 16 Posts

24 December 2010 at 1:48pm

Ok, I have tried both approaches but I am definitely doing something wrong. When I added DataObjects to my Project page they wouldn't get translated and they retained their original values. Then I switched to adding Page objects but this still doesn't work.
I'm posting my code below just in case someone is interested:
ProjectCountry.php

<?php
class ProjectCountry extends Page {

static $has_many = array(
'ProjectPages' => 'ProjectPage'
);

static $db = array(
'Name' => 'Text',
'CountryCode' => 'Text'
);

function getCMSFields_forPopup() {
$fields = parent::getCMSFields();
$fields->push( new TextField( 'Name' ) );
$fields->push( new TextField( 'CountryCode' ) );
return $fields;
}

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'CountryCode' ), 'Content' );
return $fields;
}

}
class ProjectCountry_Controller extends Page_Controller {

}
?>


ProjectPage.php

<?php
class ProjectPage extends Page {

static $db = array(
'AwardingOrganization' => 'Text',
'ProjectOwner' => 'Text'
);

static $has_one = array(
'ProjectsCountry' => 'ProjectCountry'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$tablefield = new HasManyComplexTableField(
$this,
'ProjectsCountry',
'ProjectCountry',
   array(
    'Name' => 'Country Name',
    'CountryCode' => 'Country Code'
   ),
'getCMSFields_forPopup'
);
$tablefield->setAddTitle('Project\'s Country');
$tablefield->setParentClass('ProjectPage');
$fields->addFieldToTab('Root.Content.ProjectDetails', $tablefield );
$fields->addFieldToTab('Root.Content.ProjectDetails', new TextField('AwardingOrganization'));
$fields->addFieldToTab('Root.Content.ProjectDetails', new TextField('ProjectOwner'));
return $fields;
}
}

class ProjectPage_Controller extends Page_Controller {

}
?>

Avatar
swaiba

Forum Moderator, 1799 Posts

24 December 2010 at 9:23pm

Hi,

Did you follow the doc for page translation?

http://doc.silverstripe.org/multilingualcontent?s[]=translatable
http://doc.silverstripe.org/recipes:multilingual_content?s[]=translatable

(this for nice flags for witch content)
http://www.silverstripe.org/general-questions/show/13131#post287548

Regarding the DataObject translation - I haven't done much apart from add it as an extension and try creating a translation back when I responded to that post, so there is not much I can help you there with yet...

Barry

Avatar
spyrosk

Community Member, 16 Posts

24 December 2010 at 10:13pm

Hi, yes I believe that I have followed them, but I could have done something wrong..
Right now I'm giving TranslatableModelAdmin a try. The one thing I havent figured out yet is how will I be able to display the localized dataobject on the project page (for selection on the 1 to many relationship).
It will be a shame if I can't get this to work as SS fits my needs perfectly for a CMS. :(
But I won't quit! :D

Avatar
swaiba

Forum Moderator, 1799 Posts

24 December 2010 at 10:16pm

Hi,

Maybe if you could explain a little more with where you are at I might be able to help...

Have you got the right stuff in your config.php? So you can see the option to translate a page within the cms?
Are you creating a translation for the page in the CMS? If yes to all of this, what happens when you add the code for the switching with flags to Page.ss?

Barry

Go to Top