Welcome Guest, Not a member yet? Register   Sign In
Multilanguage service


What I want to accomplish is a multilanguage web service, where language is determined by first two characters after base_url. That is, when user enters "example.com/en/someController/someMethod" it will fire up the someMethod in someController, but before doing that, it will set a global (actually defined in My_Controller) variable to 'en'.

I know I can handle this by using routes, and passing the language code as first parameter to methods, but this requires a lof of work, plus, we have a lot of existing code, and modifying it would be a nightmare.

So I thougt, that maybe using hooks is the way to go? There is a "pre_controller" hook, Is this possible to get an uri segment and then call a controller/method or maybe rather to alter routes dynamically from there?

(This post was last modified: 11-06-2014, 08:25 AM by GrigoreMihai.)

Here you go ... a fast and easy tutorial for you here. Hope this help.

p.s : I have used it to on some projects and works like a charm Wink

Multilanguage site that relies on session data isn't the best option (SEO).
You can try this library. It's a bit old but hey - it's CodeIgniter Smile it should work just fine.

Thank you both! I'll look at the links and I'll get back in case of any problems.

There you go buddy, I've been using this lib for years and never failed me.

Website: marcomonteiro.net  | Blog: blog.marcomonteiro.net | Twitter: @marcogmonteiro | TILThings: tilthings.com

(This post was last modified: 11-07-2014, 04:55 AM by konrados.)

@michalsn @marcogmonteiro

There is a problem with this library though. It doesn't recognize my other routes.
I have:
$route['^(en|es)/(.+)$'] = "$2";
$route['^(en|es)$'] = $route['default_controller'];

And it works with e.g. example.com/en/pages/contact. But then I want to add this route:
hoping this to work:
but it doesn't. I tried $route['^(en|es)contact']='pages/contact' but it doesn't work either.

Can somebody help me with this? I'm using CI v.2.2.0

Update: it actually does work with $route['en/contact']='pages/contact' although it does not work with '(es|en)/contact' - so I'm almost succeededSmile Do you by chance know why the later doesn't work?

I'm curios why do you want to use en/fr/.... in your link Smile

Is there any library available for CodeIgniter 3.0 i18n support?

Check it out here




Hi Rufnex,Great post..Really i get more information about multilanguage tutorial..Can you reply where this multilanguage concept has to apply???I am waiting for the reply..keep in touch with us..Thanks in advance Wink  Wink

Theme © iAndrew 2016 - Forum software by © MyBB