Hook that changes the current language dynamicly - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Hook that changes the current language dynamicly (/showthread.php?tid=4166) |
Hook that changes the current language dynamicly - El Forum - 11-10-2007 [eluser]Gacha[/eluser] When you will enable this hook, you will get two new global variables $GLOBALS['language'] with long language name as "english" and $GLOBALS['language-short'] as short language name as "en". 1. enable hooks in config.php 2. change uri_protocol in config.php to "PATH_INFO" 3. load url helper in autoload.php 4. create a file named language.php in hooks directory with this content: Code: <?php and modify the $languages array to suit your needs. 5. Add these lines in hooks.php config file: Code: $hook['pre_system'] = array( Now when you call yoursite.com/en/ or yoursite.com/index.php/en/ it defines the global variable for you. Please correct me if I did something wrong, because I'm new to CI. Hook that changes the current language dynamicly - El Forum - 11-21-2007 [eluser]Grahack[/eluser] Hi, I didn't test anything, so maybe everything you coded was necessary. Just thinking loud... I don't understand why you want it to act BEFORE the config loads, and I don't understand the use of $GLOBALS['language']. If we execute if later, say at 'pre_controller' time, could we simplify it this way: Code: <?php One thing is sure, you'd rather work with the short-string here! Cheers! Hook that changes the current language dynamicly - El Forum - 11-21-2007 [eluser]Gacha[/eluser] Your example is better (this was my first day with codeigniter). The short string is sometimes useful, like "some_image_en.jpg" Hook that changes the current language dynamicly - El Forum - 11-21-2007 [eluser]Grahack[/eluser] ok, I understand now the need of the short one. I think that the use of $this->config->set_item('item_name', 'item_value') and $this->config->item('item name'); is to be prefered to the $GLOBALS array. Hook that changes the current language dynamicly - El Forum - 11-21-2007 [eluser]Gacha[/eluser] You are right, thanks for recommendation. |