Multilingual website gestion |
[eluser]dorwin[/eluser]
Hi, (For the record I'm french and beginner with CI so please excuse me and if you answer, could you please use easy words ? ![]() So, I'm on a multilingual website. I found this post : http://ellislab.com/forums/viewthread/101790/P0/ very helpfull so, There im my route config : Code: $route['(en|fr)/(:any)'] = "$2/$1"; and there is a few code (wich is working (i think)) : [algo] if language is in URL (ex : site.com/en) -> loading of the lang file (here "en") else -> check navigator lang ->if navigator lang = fr or en -> redirect (rewrite the url) with $lang else ->redirect with "en" as lang Code : Code: //---CHECK LANG-----// I just developped it and i know it's optimisable, but : the question is, have I to put this code on every constructor of every controller ? I know i can put this on a function but the problem is the same, I have to call it on every constuctor ? First, is there a place I can put this code just one time and, Is my code (optimized or not) the good solution for multilingue website ? Thanks !
[eluser]flaky[/eluser]
Best would be (at least what I prefer), you write a controller which has this code (and other controlling stuff) and the other controllers extends this controller. Or as others suggest use MY_Controller. In both ways, it should work.
[eluser]dorwin[/eluser]
Damned I'm so stupid ! Thanks a lot for this tips, wich will help me for more than juste lang gestion imo ![]()
[eluser]dorwin[/eluser]
Ok, its works, I had to add few lines because it doesnt work with base URL, like site.com : Redirect is ok, ia have site.com/fr but there is not "fr" controller so: Route : Code: $route['(en|fr)/(:any)'] = "$2"; and My_Controller : Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Every others controllers extend My_Controller, wich extend Controller. Multilingual website is on good way now ![]() Thanks ! |
Welcome Guest, Not a member yet? Register Sign In |