Welcome Guest, Not a member yet? Register   Sign In
Best practice multi language support without session
#1

[eluser]Exangelus[/eluser]
Hi All,

I'm working on a project which will have to be available in both dutch and english.
Now we don't have the luxury of subdomains nor can we use sessions because it is a requirement that when people visit the website they instantly have the correct language and their will be a direct link from a portal to this website and depending on the user language setting in the portal he must get the same language here.
This leaves us with one option: putting the language in the url somewhere and I've thought of several ways to accomplish this but I'm not quit sure which is the best one (or maybe there are even better solutions):

Imagine the url like this: http://monkeys.com/nl/start/ or http://monkeys.com/en/start/

With nl/en beeing the language and start the controller.

1) Extend the router class to set the language as a config item and than further ignore the nl/ or en/ prefix and continue with routing.

2) Make a pre-system hook that user $_SERVER['REQUEST_URI'] to detect either nl/ or en/ and than set the language as config item. In the router config file I can override the nl/ and en/ prefixes using: $route['en/(:any)] = '$1';
Not sure whether I'm able to access the config class in a pre-system hook but a pre-controller hook would be too late because the router is already loaded then and thus my en/ or nl/ would already be cleared away.

3) In the router config make something like this: $route['en/(:any)'] = 'start/en/$1'; and another similair entry with nl instead of en. Then have the start controller set the language and than call another controller based on 3rd parameter in the uri.

All options have their pro's and con's and I most likely overlooked other options, what are your opinions?

Thanks in advance!
#2

[eluser]LuckyFella73[/eluser]
hi exangelus,

this library does what you need:
http://maestric.com/doc/php/codeigniter_i18n

You can set a default language and set up other languages as you need.
#3

[eluser]Exangelus[/eluser]
Thanks for the tip Lucky! ;-)




Theme © iAndrew 2016 - Forum software by © MyBB