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.

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


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 becomes

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 !



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.


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!


25 Posts

15 October 2008 at 7:55pm


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

thanks a lot for your help.


Community Member, 16 Posts

20 October 2008 at 6:13am

I have solved my problems and wrote a recipe

Maybe it helps you get started.


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:

Please help!! thank you so much!