CodeIgniter Forums
Multilanguage service - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Multilanguage service (/showthread.php?tid=161)



Multilanguage service - konrados - 11-06-2014

Hi,

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?


RE: Multilanguage service - GrigoreMihai - 11-06-2014

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


RE: Multilanguage service - michalsn - 11-06-2014

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.


RE: Multilanguage service - konrados - 11-06-2014

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


RE: Multilanguage service - marcogmonteiro - 11-07-2014

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

http://jeromejaglale.com/doc/php/codeigniter_i18n


RE: Multilanguage service - konrados - 11-07-2014

@michalsn @marcogmonteiro
Thanks.

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:
$route['contact']='pages/contact';
hoping this to work:
example.com/en/contact
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?


RE: Multilanguage service - GrigoreMihai - 11-07-2014

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


RE: Multilanguage service - karthik_code - 12-27-2014

Is there any library available for CodeIgniter 3.0 i18n support?


RE: Multilanguage service - Rufnex - 12-27-2014

Check it out here

https://github.com/bcit-ci/CodeIgniter/wiki/i18n-Multi-language-Library-Helper
https://github.com/bcit-ci/CodeIgniter/wiki/CodeIgniter-2.1-internationalization-i18n

https://github.com/Crypt/CodeIgniter-i18n


RE: Multilanguage service - benny - 12-30-2014

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