3237 Posts in 943 Topics by 684 members
|Go to End|
9 May 2011 at 7:41pm
I ran into a problem with creating content for a multilingual website (English and Thai) which I now think I have resolved but would appreciate peer review from those who understand the internals of Silverstripe better than I do.
The scenario was one of this - a user can register to the site and then contribute material, in this case a suggested link, to the webmaster. The intention was to use the fields from this form to create a Link object (containing a title, description and website url) in the database, unpublished, and email the web master. He or she can then decide whether to reject the submission or drag and drop it to an appropriate place in the website.
I found some code examples that suggested the following:
$link = new Link();
$link->ParentID = $this->ID;
$link->Title = 'Whatever';
$link->Url = 'http://www.whatever.com';
$link->Description = 'This is a description of whatever.com';
// publication of this item not required, will be done manually by the webmaster
Now this worked in the en_US version of the website, but *not* the th_TH version (Thai). When I looked in the database I observed the following:
1) The parent ID of the Link object is a page in the Thai SiteTree, with locale th_TH
2) The newly created Link had a locale of en_US
Things are kind of broken now, as data is in the database but not rendering in the SiteTree in /admin/cms. After I realised the locale issue I changed the code above to end with
$link->Locale = Translatable::get_current_locale();
This resolved the issues I was observing.
So in short if you are working outside of the en_US site tree you need to both set the parentID *and* the locale to see the new item correctly placed both on the site and the administrative interface.
9 May 2011 at 9:50pm
I remember there being an issue with translatable DataObjects and the setting of the correct locale. Don't know if this would solve the initial problem in your setup, but just in case... See this ticket/patch:
10 May 2011 at 12:21am
Thanks for that pointer - I will add the existence check for the Translatable class to my code
|Go to Top|