Switch language helper on runtime
I have a cron which calls a controller.
It makes a batch process that sends notifications to users.
I need to send a message with a different language for different user idioms.
I tried this but it does not work:
//SPANISH
$this->config->set_item('language', 'es');
$this->load->language('project');
$msg1 = lang('push-challenge-ask');
//PORTUGUESE
$this->config->set_item('language', 'pt');
$this->load->language('project');
$msg2 = lang('push-challenge-ask');
echo $msg1;
echo $msg2;
It echoes in spanish two times. Like if the second time I call the language helper it does not load / change.
I suppose this could be on purpouse related to performance times.
How can I change dynamically the language?
Can I unload and load the helper?
Is there another option to switch languages in runtime?
Thank you
Comments
https://ellislab.com/forums/viewthread/150122
It only loads the first language and repeats in the array.
In my example it loads the two times in spanish even if the second time I load
$project_pt = $this->lang->load('project', 'pt', true);
$msg2 = $project_pt['push-challenge-ask'];
(as the link you gave me indicates).
I will search in the CI docs, but could it has something to do with Fuel's own language helper?
Thank you
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
you are right!, the solution is to reset the is_loaded!
$this->lang-> is_loaded=array();
Thank you!