CodeIgniter Forums
languages in application - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: languages in application (/showthread.php?tid=6413)



languages in application - El Forum - 02-26-2008

[eluser]chejnik[/eluser]
Hello, I would like to ask you what is the best way to use different languages in application.

I would prefer the users choose their language at the beginning in form element.
How can I change the language?

I have tried this with autoload of the language files with deafult language in config file
Code:
$this->config->set_item('language', $_POST["lang"]);

but no change in languages.

I have tried this with same result
Code:
$this->lang->load('user', $_POST["lang"]);

And second question - is it good idea to load all languages files or is it better to load them one by one? I expect there will be just 4 languages with 10 files with 100 strings.

Thanks Ales


languages in application - El Forum - 02-26-2008

[eluser]xwero[/eluser]
i've written a few times about how i deal with languages but i'm too lazy to search for it. check out MY_Language in the wiki were you will find the switch_to method useful.

For your second question why store 4 languages in memory if three are not going to be used? It's different if you have multi language pages, then you have no choice but to load all the languages.


languages in application - El Forum - 02-26-2008

[eluser]chejnik[/eluser]
That doesnot answer my first questions, but thank you. I would like to know ordinary method to switch between language files. I agree with you that is not good to store all languages that are not actually to be used.
Ales


languages in application - El Forum - 02-26-2008

[eluser]xwero[/eluser]
There is no ordinary method to switch between languages. The language library isn't that advanced. It only can add files with language strings to the language array and read a string from the language array based on the key of the string.


languages in application - El Forum - 02-26-2008

[eluser]chejnik[/eluser]
Ok, thanks. I ll have a look at your library more closely. If anything is unclear to me, I ll send post.
Thank you Ales


languages in application - El Forum - 02-26-2008

[eluser]xwero[/eluser]
You can desql the method names if you want, it was a part of my sqlize data extraction for non database libraries idea (language, session, input) but i haven't had time to do the other libraries.


languages in application - El Forum - 02-26-2008

[eluser]chejnik[/eluser]
Hello, it works for me. Thank you.
I have still two questions - first - generally I have to include these two lines whenever I ll send data to view -

$this->lang->load('thenameofthelanguagefile');
$this->lang->switch_to($this->session->userdata('language'))Wink);

And second - I did not have to even autoloaded MY_Language class, I have just placed it in Library directory in application folder and it began to work. How it this possible Smile ?
Ales


languages in application - El Forum - 02-26-2008

[eluser]xwero[/eluser]
You can put it in the construct method of your class or you could create a base class where you put it in the construct method. All other classes that you extend from this class will have that ability to switch languages.

CI looks for libraries with the MY_ prefix in the application/libraries directory and if they are found the parrent class is added with the child class. It works for most libraries.


languages in application - El Forum - 02-26-2008

[eluser]chejnik[/eluser]
Great, thank you for help. It is quiet interesting and helpful. All the best Ales