CodeIgniter Forums
Changing language - 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: Changing language (/showthread.php?tid=34106)



Changing language - El Forum - 09-19-2010

[eluser]WoolyG[/eluser]
Hi all,

If I have 2 languages - say, english and spanish, and relevent language files set with equivalent listings for each line, how would I easily flick between the two languages?

I'm thinking a jump menu that changes a session setting relating to the language that the viewer would like to see the site in, but how would I load the language in question for the person viewing the site, using the session variable?

All info appreciated.
WoolyG


Changing language - El Forum - 09-19-2010

[eluser]Akinzekeel[/eluser]
I used to load the language in a pre_controller hook.

In this hook I first check if there is a language set in $this->CI->session->userdata. Depending on this, I either load the default language or the one which has been stored for this session.

If the user wishes to change the language, I call a public change_language controller-method with two arguments: the language and a base64-encoded URL of the page which is currently displayed. The method will then simply save the new language to the session, decode the base64 URL and redirect back to it.

Since the new language is now stored in the session, the hook will load that language as mentioned above.


Changing language - El Forum - 09-19-2010

[eluser]WoolyG[/eluser]
Cool. I'll have a read about the process you mention, and look into implementing it. Thanks for your reply!
WoolyG.


Changing language - El Forum - 09-19-2010

[eluser]wiredesignz[/eluser]
try the URI Language Identifier extension. Having the language id in the url also makes each page unique to search engines.