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

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?
Reply
#2

(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
Reply
#3

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.
Reply
#4

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

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

http://jeromejaglale.com/doc/php/codeigniter_i18n
Website: marcomonteiro.net  | Blog: blog.marcomonteiro.net | Twitter: @marcogmonteiro | TILThings: tilthings.com
Reply
#6

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

@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?
Reply
#7

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

Is there any library available for CodeIgniter 3.0 i18n support?
Reply
#9

Check it out here

https://github.com/bcit-ci/CodeIgniter/w...ary-Helper
https://github.com/bcit-ci/CodeIgniter/w...ation-i18n

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

Reply
#10

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB