I added the following three functions to includes.php:
[code:1]
function uddeIMgetLanguageFromID ($id, $config)
{
$user = &JFactory::getUser ($id);
$lang = &JFactory::getLanguage ();
$user_language = $user->getParam ('language', $lang->getDefault);
$user_lang = new JLanguage ($user_language);
$language = strtolower ($user_lang->getBackwardLang());
return $language;
}
function uddeIMgetConstant ($buffer, $config, $constant)
{ // Search for the constant's value in buffer.
$pos = strpos ($buffer, $constant);
if ($pos === FALSE)
return $constant;
else
{
$pos += strlen ($constant); // Jump over the constant itself.
$pos += 1; // " or '.
// Find the comma.
while (substr ($buffer, $pos, 1) != "," && substr ($buffer, $pos, 1) != ""«»)
$pos ++;
if (substr ($buffer, $pos, 1) == ""«») // Syntax error.
return $constant;
$pos ++; // Jump over the comma.
// Jump over white space if there is any..
while (
substr ($buffer, $pos, 1) != "" &&
(substr ($buffer, $pos, 1) == " " || substr ($buffer, $pos, 1) == "\t" || substr ($buffer, $pos, 1) == "\n"«»)
)
$pos ++;
// Check if it's a single or a doube quotation mark.
if (substr ($buffer, $pos, 1) == "\"" || substr ($buffer, $pos, 1) == "'"«»)
$char = substr ($buffer, $pos, 1);
else
return $constant; // Anything else is an error.
$pos ++; // Jump over the quotation mark.
$pos_e = strpos ($buffer, $char, $pos);
if ($pos_e === FALSE)
return $constant; // Error.
$value = substr ($buffer, $pos, $pos_e - $pos);
// Some replacements.
$value = str_replace ("\\n", "\n", $value);
$value = str_replace ("\\t", "\t", $value);
return $value;
}
}
function uddeIMgetConstantForLanguage ($backward_lang, $config, $constant)
{ // Retrieve a language constant as a variable.
$pfx = "";
if ($config->languagecharset)
$pfx = ".utf8";
$the_langfile = JPATH_SITE . "/administrator/components/com_uddeim/language" . $pfx . "/" . $backward_lang . ".php";
if (file_exists ($the_langfile))
{
$fh = fopen ($the_langfile, "r"«»);
$contents = "";
while (!feof ($fh))
$contents .= fread ($fh, 8192);
fclose ($fh);
$value = uddeIMgetConstant ($contents, $config, $constant);
if ($value == $constant)
{ // Give it another go with the German language file (i = informal, f = formal).
$the_langfile = JPATH_SITE . "/administrator/components/com_uddeim/language" . $pfx . "/" . $backward_lang . "i.php";
if (file_exists ($the_langfile))
{
$fh = fopen ($the_langfile, "r"«»);
$contents = "";
while (!feof ($fh))
$contents .= fread ($fh, 8192);
fclose ($fh);
$value = uddeIMgetConstant ($contents, $config, $constant);
} else
return $constant;
}
return $value;
} else
return $constant;
}
[/code:1]
The first one is to retrieve a user's language, the second one to read the value of a language constant, the third one to read a language file.
Then, further in includes.php, I'm calling the functions just after these lines (old):
[code:1]
$var_toname = uddeIMgetNameFromID($var_toid, $config);
$var_tomail = uddeIMgetEMailFromID($var_toid, $config);
[/code:1]
New:
[code:1]
$var_toname = uddeIMgetNameFromID($var_toid, $config);
$var_tomail = uddeIMgetEMailFromID($var_toid, $config);
$j_version = JVERSION;
$j_version = substr ($j_version, 0, 4);
$j_version = str_replace (".", "", $j_version);
if (intval ($j_version) >= 15)
{ // Retrieve the recipient's language so that he/she receives the emails in their language...
$var_tolang = uddeIMgetLanguageFromID ($var_toid, $config);
// ...and prepare the message in that language.
$_UDDEIM_EMN_FORGETMENOT = uddeIMgetConstantForLanguage ($var_tolang, $config, "_UDDEIM_EMN_FORGETMENOT"«»);
$_UDDEIM_EMN_BODY_WITHMESSAGE = uddeIMgetConstantForLanguage ($var_tolang, $config, "_UDDEIM_EMN_BODY_WITHMESSAGE"«»);
$_UDDEIM_EMN_BODY_NOMESSAGE = uddeIMgetConstantForLanguage ($var_tolang, $config, "_UDDEIM_EMN_BODY_NOMESSAGE"«»);
$_UDDEIM_EMN_SUBJECT = uddeIMgetConstantForLanguage ($var_tolang, $config, "_UDDEIM_EMN_SUBJECT"«»);
} else
{
$_UDDEIM_EMN_FORGETMENOT = _UDDEIM_EMN_FORGETMENOT;
$_UDDEIM_EMN_BODY_WITHMESSAGE = _UDDEIM_EMN_BODY_WITHMESSAGE;
$_UDDEIM_EMN_BODY_NOMESSAGE = _UDDEIM_EMN_BODY_NOMESSAGE;
$_UDDEIM_EMN_SUBJECT = _UDDEIM_EMN_SUBJECT;
}
[/code:1]
Another few lines further, I changed
[code:1]
$var_body = _UDDEIM_EMN_FORGETMENOT;
[/code:1]
to
[code:1]
$var_body = $_UDDEIM_EMN_FORGETMENOT;
[/code:1]
The same goes for the constants _UDDEIM_EMN_BODY_WITHMESSAGE, _UDDEIM_EMN_BODY_NOMESSAGE, and _UDDEIM_EMN_SUBJECT:
[code:1]
if($emn_option==1) {
$var_body = $_UDDEIM_EMN_FORGETMENOT;
$var_body = str_replace("%livesite%", $pathtosite, $var_body);
$var_body = str_replace("%you%", $var_toname, $var_body);
$var_body = str_replace("%site%", $mosConfig_sitename, $var_body);
$var_body = str_replace("%msglink%", $msglink, $var_body);
} else {
if($config->emailwithmessage==1 || $emn_option==2) {
$var_body = $_UDDEIM_EMN_BODY_WITHMESSAGE;
$var_body = str_replace("%livesite%", $pathtosite, $var_body);
$var_body = str_replace("%you%", $var_toname, $var_body);
$var_body = str_replace("%site%", $mosConfig_sitename, $var_body);
$var_body = str_replace("%msglink%", $msglink, $var_body);
$var_body = str_replace("%user%", $var_fromname, $var_body);
$var_body = str_replace("%pmessage%", $var_message, $var_body);
} else {
$var_body = $_UDDEIM_EMN_BODY_NOMESSAGE;
$var_body = str_replace("%livesite%", $pathtosite, $var_body);
$var_body = str_replace("%you%", $var_toname, $var_body);
$var_body = str_replace("%site%", $mosConfig_sitename, $var_body);
$var_body = str_replace("%msglink%", $msglink, $var_body);
$var_body = str_replace("%user%", $var_fromname, $var_body);
}
}
$subject = $_UDDEIM_EMN_SUBJECT;
[/code:1]
Users now receive the notification emails in the language of their choice.
I'd be grateful it if this (or similar) could make it in one of the next versions of uddeIM.