Welcome Guest, Not a member yet? Register   Sign In
Best approach to send a notification internationalized
#1

[eluser]Muser[/eluser]
Hi, I have searched inside the forum and I didn't found any solution about it.

We have a social network site, where each user have his language as default. Currently we are suporting catalan, spanish and euskera languages. We coded a notification system that sends an email to the user when, for example, another user replied a message to the wall. The problem occurs when an user with language euskera do an action to a user with language, for example, catalan, the catalan user receives an email with euskera language inside.

We coded a "reload()" method to the class MY_Language to reset the current language defined.

Then, we want to do:

1. Store the current language of the logged in user that makes the action.
2. Collect all the users that must to be notified about the action, ordered by language.
3. Loop users result and send the message to them. During the loop If the language changes, call the reload() method.
4. Restore the language of the logged in user with reload() method.

Do you suggest another approach to get this thing done?

Thank you!
#2

[eluser]tomcode[/eluser]
That's how I do it, too Wink
#3

[eluser]WanWizard[/eluser]
I just load the required files in my controller:
Code:
$languages = array();
foreach ($items as $item)
{
    // get the language file if needed
    if ( ! isset($languages[$item['langcode']]) )
    {
        $languages[$item['langcode']] = $this->load->lang('langfilename'], $item['langcode'], TRUE);
    }

    // compose and send the message
   $this->send_message($item, $languages[$item['langcode']]);
}

This way you don't have to fiddle with the current users' language selection, and you don't "contaminate" the loaded language strings...
#4

[eluser]Muser[/eluser]
Nice!!!

I will use WanWizard's trick.

I had not realized the third optional parameter for $this->lang->load !!

Thank you for your suggestions Smile




Theme © iAndrew 2016 - Forum software by © MyBB