Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Wisa.nl

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

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

Page: 1 2 3
Go to End
Author Topic: 37289 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Wisa.nl Link to this post

    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

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Wisa.nl Link to this post

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

  • ScottiouS
    Avatar
    Community Member
    54 Posts

    Re: Wisa.nl Link to this post

    Site looks great!

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

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Wisa.nl Link to this post

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

  • poblom
    Avatar
    Community Member
    25 Posts

    Re: Wisa.nl Link to this post

    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

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Wisa.nl Link to this post

    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.

  • poblom
    Avatar
    Community Member
    25 Posts

    Re: Wisa.nl Link to this post

    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

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: Wisa.nl Link to this post

    Hmm..

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

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