Multilingual application - 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: Multilingual application (/showthread.php?tid=62989) |
Multilingual application - Camo - 09-14-2015 Hi, I am trying to find out how to make the web multilingual. Can you tell me please, what is the best practice? I have routes like this: Code: $route['((en|cz)/)?test'] = 'test/index'; In MY_controller I do this: PHP Code: public $language = 'sk'; // should not be protected??? But I can not call it in template if it is protected Is it the right way to use? Thanks. RE: Multilingual application - rtorralba - 09-14-2015 (09-14-2015, 12:06 PM)Camo Wrote: Hi, Hi, You can use the following regular expresion for routes: Code: $route['^(\w{2})/(.*)$'] = '$2'; And to can pass variables to views you can use a protected variable to add all variables that you will use at your views: MY_Controller: PHP Code: class MY_Controller extends CI_Controller Example controller: PHP Code: class Example extends MY_Controller RE: Multilingual application - Camo - 09-14-2015 Thanks $view_data in MY_controller is a good idea. But this route $route['^(\w{2})/(.*)$'] = '$2'; wont work if I want to call e.g. home/index/7 ??? Am I right? And what about that slash? Here it is non optional part of that regexp. Is that ok? RE: Multilingual application - rtorralba - 09-14-2015 (09-14-2015, 03:14 PM)Camo Wrote: Thanks $view_data in MY_controller is a good idea. I think would be good that you have a default language and if always use it and redirect / (segment(1) empty) to /en (default language) RE: Multilingual application - Camo - 09-14-2015 Default language should be invisible. That's ok it works fine. Have a nice day. RE: Multilingual application - rtorralba - 09-15-2015 (09-14-2015, 04:26 PM)Camo Wrote: Default language should be invisible. That's ok it works fine. Have a nice day. Rate it please. |