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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Wisa.nl


Go to End


17 Posts   39065 Views

Avatar
dio5

Community Member, 501 Posts

3 July 2008 at 4:37am

Your approach to solve the languages seems interesting.

Did you make an action for every language?

Looking at the urls you have:

http://www.wisa.nl/wisa-team/DE/wisa-team

Would be cool if you documented somewhere in a few steps how this approach was... would be a favor to a lot of us :)

Avatar
Fuzz10

Community Member, 791 Posts

4 July 2008 at 7:10am

Yeah , sure ! I'm on vacation ATM but I'll make sure to document it when I get back (end of July).

Avatar
ScottiouS

Community Member, 54 Posts

18 July 2008 at 8:35pm

Site looks great!

Something a little starge with the URLs there though..http://www.wisa.nl/feesttoeters//feesttoeters

Avatar
Fuzz10

Community Member, 791 Posts

28 July 2008 at 10:22pm

Edited: 28/07/2008 10:24pm

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-------------------

Avatar
poblom

Community Member, 25 Posts

31 July 2008 at 12:45pm

Nice job Fuzz10!

I an trying your ideas on a current project and am a little confused. I wonder if you could describe a little more in detail how the menus are generated. I guess it's not the usual <% control Menu(1) %>.
I can switch the contents in my custom fields but menus does not work since the Menu-function is reading from SiteTree. So inside the control-statement my custom Title and MenuTitle is not available.

Would be very kind if you could explain a little more.

/PO

Avatar
Fuzz10

Community Member, 791 Posts

31 July 2008 at 7:13pm

I'm using the normal control Menu(1).

Because I have created a method named Title in my Page Class , the menu items will get translated as needed.

Avatar
poblom

Community Member, 25 Posts

31 July 2008 at 10:06pm


Really don't understand that because I actually "copied" your code, including functions for Title and MenuTitle. So I have them to but no translated values. No problem thou to get the translated values for Content or other custom fields. Weired!!

Instead I hacked the Menu() function in ContentController and changed the Title and MenuTitle values there, and it works. Not a beautiful hack but...!

Now I only have to hack MetaData to show the right page title.

Still really confused why I could not retrieve the translated values in the page controller.

/PO

Avatar
Fuzz10

Community Member, 791 Posts

1 August 2008 at 9:31pm

Hmm..

Make sure the function is in your Page class , not in your page_controller .....