Dio :
I wrote up a little howto.
Did not know where to put it , so check out the comments on this page :
http://doc.silverstripe.com/doku.php?id=multilingualcontent
Integral copy-paste (to make sure it is on the forum as well , with regards to PPL searching).
-------------------snip-------------------
This comment is In reply to http://www.silverstripe.com/showcase-forum/flat...
While the multi-language features of Silverstripe are still pretty much Work In Progress I used the following work-around to create a multiple language site which contained custom fields. There is probably a cleaner way , and this only works with simple sites and not too many languages...but hey... it works.
1> Duplicate the fields you want translated for every language (for example , in my case , for the $Title I created DE_Title and NE_Title)
2> Add these fields to the Silverstripe backend with AddFieldToTab so users can edit them.
4> Add language-switching links to your template , in my case , I add a $GET parameter named lang to the URL . e.g. www.mysite.com?lang=EN
3> In the INIT of your base page class controller (usually Page_Controller) , check for the language $GET param and if it exists , set the current language in the session..
E.g. :
if(!empty($_REQUEST['lang'])) {
Session::set('lang', $_REQUEST['lang']);
}
Now you know what the current language should be.
4> In your base Page Class, create custom getters for the content-fields so they return the right value for the current language Check for the existence of the Lang variable in the session to figure out the current language. My default language is Dutch....
(e.g.
function Title() {
if(Session::get('lang') == "EN"){
return $this->EN_Title;
} elseif(Session::get('lang') == "DE") {
return $this->DE_Title;
} else {
return $this->Title;
}
}
5> Create a function to obtain the current language (we use these in templates)
function current_language() {
return Session::get('lang');
}
6> To make the URL's somewhat Multi-lingual as well , I add the current language and the translated page title to the URL .... So in my case , the default URL www.mysite.com/over_ons would become www.mysite.com/over_ons/DE/uber_uns for the german version.
To do this, just combine the needed variables in your templates , e.g..
href="$Link{$current_language}/{$URLTitle}"
Where $URLTitle is the translated and URL-safe page-title....
If you do this, make sure to catch the method call SS does when it finds an action parameter in the URL ... (the "DE" in www.mysite.com/over_ons/DE/uber_uns)...
So in my page_controller class i Created these dummy methods to reroute the request back to the original page:
// Dummy methods to catch the language-vars in URL
function DE() {
return $this->renderWith($this->getViewer());
}
function EN() {
return $this->renderWith($this->getViewer());
}
function NL() {
return $this->renderWith($this->getViewer());
}
I whipped up this text in a hurry, so let me know if I forgot something or screwed something up.... ;)
-------------------snip-------------------