Switch language helper on runtime

edited October 2014 in Modules
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

  • edited 10:35AM
    Looks like you can load it and have it return as a variable as explained here (this is a CI thing):
    https://ellislab.com/forums/viewthread/150122
  • edited 10:35AM
    I tried that but it Still does not work.
    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
  • edited 10:35AM
    FUEL does overwrite the Lang class using the HMVC library and that file is located in fuel/application/third_party/MX/Lang.php. However, I think you'd run into the same problem with the native CI Lange class as well. It only loads the same language file once for any language (idiom). To clear it out, you may need to reset the $this->lang->language variable which gets populated on the class or the $this->lang-> is_loaded variable.
    https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
  • edited 10:35AM
    ok!
    you are right!, the solution is to reset the is_loaded!
    $this->lang-> is_loaded=array();

    Thank you!
Sign In or Register to comment.