Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17478 Posts in 4473 Topics by 1972 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.

Page: 1
Go to End
Author Topic: Adding language code in front of URL segment - where ? 1582 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
    602 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!

    1582 Views
Page: 1
Go to Top

Currently Online: banal

Welcome to our latest member: Eco

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.