Reputation: 3715
I want the user to select his language from any sub page on my website. The best solution, to store each user language are sessions.
My website default language is English, but how should I load other language that user select? I guess I should do it like this:
$this->lang->load('my_language_file', $this->session->userdata('language'));
But this way, I'd have to load the language in every controller.
Isn't there a way, to select user language from session globally? So I could use $this->lang->line('some-message');
in every place on my website?
Upvotes: 1
Views: 899
Reputation: 10996
Either do a
$CI =& get_instance();
$CI->lang->load('my_language_file', $CI->session->userdata('language'));
in the beginning of a custom helper and have it autoloaded in your config/autoload.php.
Else you can do it through hooks.
Basicly use
$CI =& get_instance();
$CI->lang->load('my_language_file', $CI->session->userdata('language'));
here aswell inside the __construct(), and have the Hook Point post_controller_constructor
.
This will make you include the lang file in all controllers. However it's up to you how much lang-text you want to load automaticly, since it exhausts the server even if only to a small extent.
Upvotes: 4