Internationalization support in CI 2.0 |
[eluser]ssachan[/eluser]
I always thought that there should be a more easy and automated way to include internationalization support. I believe it is almost a standard way to URLs as follow base-url/en/controllers base-url/fr/controllers .. and so on for different languages. And a flag value set anytime during runtime should be able to govern that. So if my user selects a language during loggin in, he should have the site in that language.
[eluser]Clooner[/eluser]
It's really easy to do with CI... almost no code required...
[eluser]ssachan[/eluser]
no its not. have a look at this library which does what I am talking about http://maestric.com/doc/php/codeigniter_i18n its pretty clear it requires lots of alteration in routes.php, controllers, etc. and its more complicated if you are using HMVC/ Modular Extensions. If you have an easy implementation, please do point out. Thanks for increasing my knowledge as well Shikhar
[eluser]Clooner[/eluser]
Basically the only thing you need to do is add 2 regex routes to make the urls work, set the language in the config file according to the first segment(could be easily done with two lines of code in a my_controller. The library you describe is just a way of doing things which although maybe a bit verbose it's easy to understand. There is also a place where you can download the CI language files which are available in almost every language.
[eluser]ssachan[/eluser]
Hello Jeroen, thanks for your inputs. Can you help me a little more. I am playing with the code. My initial settings are 1. CI 2.0 where by default I don't see the index.php 2. HMVC perfectly installed. First I put these lines in my routes.php $route['^en/(.+)$'] = "$1"; $route['^en$'] = $route['default_controller']; Now when my url is site_url/en, it should be routed to the default controller which in my case happens to be 'welcome'. But this doesn't seem to work. I have no clue why? is there an issue with the routes. I am thinking once I get this working I will move to fiddling with My_Controller and overriding default lang. thanks for the help
[eluser]Clooner[/eluser]
Are you getting any errors and is the default(without language prefix) controller working?
[eluser]ssachan[/eluser]
no I am not getting any error http://localhost:8888/Stream 2.0/codeigniter displays my welcome page correctly (I have the Modular Extensions files and they seem to be working fine since I get to see the welcome page) but http://localhost:8888/Stream 2.0/codeigniter/en gets me a 404 page not found. I have not done anything just added the above lines in the routes.php. Once I get this running, I will document it for the rest of the community to use. Please do point out any debugging tips if you want some more info on the same
[eluser]Clooner[/eluser]
Because of the 404 it seems your routes are not working. try Code: $route['\w{2}'] = "welcome";
[eluser]ssachan[/eluser]
Exactly the same behavior. How do I get my routes working. Have you given a shot at CI 2.0 with internationalization. You may want to ... if there is a bug in the core classes it makes sense to report it. |
Welcome Guest, Not a member yet? Register Sign In |