![]() |
[SOLVED] How do I switch languages. newby! - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: [SOLVED] How do I switch languages. newby! (/showthread.php?tid=26637) |
[SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]chefnelone[/eluser] hi. Just starting my first multilingual site with ci. I already have the languages folder in: system/language/ But I have no idea how to manage the language switcher using something like: <ul> <li><a href="#">French</a></li> <li><a href="#">Spanish</a></li> <li><a href="#">Dutch</a></li> </ul> looking for a tutorial or thread where I can start with ? [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]JHackamack[/eluser] What I've researched is doing something like setting a session variable that contains the language to use. You can set it with a function in a controller and redirect back to the current page. Code: $this->lang->load('alerts',$this->session->userdata('language')); [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]chefnelone[/eluser] [quote author="JHackamack" date="1263931127"]What I've researched is doing something like setting a session variable that contains the language to use. You can set it with a function in a controller and redirect back to the current page. Code: $this->lang->load('alerts',$this->session->userdata('language')); I can't get your point, I need beginner's guidelines to do this. I just need to switch the language from english to spanish. Which is the variable I need to change? [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]JHackamack[/eluser] There is no variable predefined in CodeIgniter. To maintain a users language preferences across multiple pages you'd need to use a session variable, or a cookie. I prefer session variables so thats how I wrote my example. Since you're asking about languages I'm assuming you've read the language user guide documentation and know how to do $this->lang->load(). I'll provide you an example of what setting the language variable might look like Code: /** [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]chefnelone[/eluser] this is what I've done: in applications/controller/home.php Code: <?php in application/views/home.php Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> When I first load it, it shows the the correct text: Code: The email validation method must be passed an array. Then I clic on Spanish links and it still loads the text in english. Instead of the spanish version. I already have the 'spanish' folder inside: 'system/language/' What am I doing wrong?? [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]JHackamack[/eluser] I believe the language should be /Application/Language/ folder Rather than /System/Language [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]chefnelone[/eluser] [quote author="JHackamack" date="1263939151"]I believe the language should be /Application/Language/ folder Rather than /System/Language[/quote] I tried it. But still no working. Should I load the spanish language in config.php? [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]JHackamack[/eluser] Right before you load the language can you: Code: echo $this->session->userdata('language'); [SOLVED] How do I switch languages. newby! - El Forum - 01-19-2010 [eluser]chefnelone[/eluser] solved! there was a typo mistake: $this->session->set_userdata('lang',$this->uri->segment(3)); must to be $this->session->set_userdata('language',$this->uri->segment(3)); thanks JH. |