Welcome Guest, Not a member yet? Register   Sign In
Language indicator in URL
#1

[eluser]mDonchev[/eluser]
Hello all,

I want to put a language indicator in the URLs generated in the CI website like this:
www.example.com/en/controler/function/parametter

I want this "en" to be "read" by the router, set a session variable and then to load the proper controler/funciton/parametter.

Note: I want the URL to stay as it is. Not to redirect to www.example.com/controler/function/parametter

Please tell me how I can achieve that.

THanks
Martin
#3

[eluser]mDonchev[/eluser]
Thanks
I read that with one eye, but I've done something different as a solution and I'm aaaalllmost done.

I've rewrote the URLs so that the first segment to be the language indicator, and I'm rewriting the Router.php class so that it sets the language indicator as a session variable and exclude it from the segments so that everything goes as normal as it would be without that language indicator in the URL.

I'm having a slight problem with setting the session because the session class is not loaded in the Router.php and I cannot load it.. so I'm trying to use pure PHP for setting that session.

Thanks
Martin
#4

[eluser]mDonchev[/eluser]
Any ideas how I can load the session library inside the Router.php (note that its used too early in the loading process so the Loader is not available yet!)

Thanks
Martin
#5

[eluser]xwero[/eluser]
Why would you need to change the router. You just set a route to redirect each url that has a language segment
Code:
$route['[a-z]{2}/(.+)'] = '$1'; // regex may not work
You use that first segment where you need it or use the default language if the language segment isn't set.
And you overwrite the url creating functions to add the language segment or just append the language segment to the index_page with a hook function.

Having as config file with the language, an url with the language and on top of that a session with the language isn't that too much redundance?
#6

[eluser]phpwebdev[/eluser]
Здравей Мартине,

Не разбирам защо трябва пазиш езика в сесията. По добре от гледна точка на SEO -то да бъде в урл-то

Аз използвам една библиотека която използва нещто като

http://www.server.com/bg/controller/function/
http://www.server.com/en/controller/function/

И нямам оплаквания .....

Ето и линка

http://codeigniter.com/wiki/URI_Language_Identifier
#7

[eluser]Treeda[/eluser]
if you would use english like nearly everyone in that forum, quite a lot more people could benefit from your answer.
#8

[eluser]Vicente Russo[/eluser]
Hi,

Maybe this could help. basicly its the same solutio, but working with templates.

V.




Theme © iAndrew 2016 - Forum software by © MyBB