Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Adding language code in front of URL segment - where ?

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

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

Page: 1
Go to End
Author Topic: 3526 Views
  • Skipper
    Avatar
    Community Member
    16 Posts

    Adding language code in front of URL segment - where ? Link to this post

    Good evening.

    Can someone give me a hint at what part of the core the URL is constructed? What I want is to add currentLang() in front of the "ordinary" URI so that mysite.com/about-us/ becomes mysite.com/en/about-us/

    I am staring at the Director and am tempted to add some Translatable::currentLang() here and there, but that baby is quite pasta-like to me. Is there a better, safer, place to find my happiness?

    This is the last issue before I have my i18n with nice URLs and pretty links - help please !

    Thanks!

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Adding language code in front of URL segment - where ? Link to this post

    This line in your _config.php should get you started:

    Director::addRules(2, array(
       '$Lang/$URLSegment/$Action/$ID/$OtherID' => 'ModelAsController'
    ));

    Then you'll need to modify your .htaccess file so that the the $Lang bit gets changing into the lang query parameter before it gets sent to sapphire. Something like:

    RewriteRule ^(\D+\/)(.*)$ sapphire/main.php?lang=$1&url=$2&%{QUERY_STRING} [L]

    And then... maybe Director::setBaseURL($lang), but I'm not sure how to get the current language from the _config.php file. Maybe you'll need to create a custom controller to send requests to the right place. Also, it breaks the CSS and images..

    Not sure where too from there, but maybe I gave you some ideas.

  • Skipper
    Avatar
    Community Member
    16 Posts

    Re: Adding language code in front of URL segment - where ? Link to this post

    Thanks, Hamish !

    It is the part in your reply "And then ... maybe" where I am exactly. All else is fine already. I need to hack Director now, and maybe some other places to get my URLs right.

    I'll go with trial and error now; I love it!

    Thanks again!

  • François
    Avatar
    25 Posts

    Re: Adding language code in front of URL segment - where ? Link to this post

    Hello!

    Any results? A recipe to follow maybe? Any solution to solve the broken CSS and images path?

    thanks a lot for your help.

  • Skipper
    Avatar
    Community Member
    16 Posts

    Re: Adding language code in front of URL segment - where ? Link to this post

    I have solved my problems and wrote a recipe http://doc.silverstripe.com/doku.php?id=recipes:pretty_i18n_urls

    Maybe it helps you get started.

  • kudesign
    Avatar
    Community Member
    64 Posts

    Re: Adding language code in front of URL segment - where ? Link to this post

    Hi, I tried it, followed it exactly, but not sure what went wrong? this is my test site: http://kuholdings.com/demo/

    Please help!! thank you so much!

    3526 Views
Page: 1
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.