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

Adding language code in front of URL segment - where ?


Go to End


6 Posts   4529 Views

Avatar
Skipper

Community Member, 16 Posts

14 September 2008 at 7:36am

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!

Avatar
Hamish

Community Member, 712 Posts

15 September 2008 at 1:09pm

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.

Avatar
Skipper

Community Member, 16 Posts

15 September 2008 at 4:59pm

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!

Avatar
François

25 Posts

15 October 2008 at 7:55pm

Hello!

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

thanks a lot for your help.

Avatar
Skipper

Community Member, 16 Posts

20 October 2008 at 6:13am

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.

Avatar
kudesign

Community Member, 64 Posts

27 November 2008 at 1:15am

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!