Skip to Content Skip to Menu

Notification messages sent in wrong language

  • slabbi
  • slabbi
  • OFFLINE
  • Posts: 3709
  • Thanks: 250
  • Karma: 153
14 years 3 months ago #139290 by slabbi
Don't forget that there are still Joomla 1.0 users ;)

uddeIM & uddePF Development
CB Language Workgroup
CB 3rd Party Developer

Please Log in or Create an account to join the conversation.

  • Theo01
  • Theo01
  • OFFLINE
  • Posts: 16
  • Thanks: 0
  • Karma: 0
14 years 3 months ago #139304 by Theo01
The other issue is that all language-specific texts are in constants.

Please Log in or Create an account to join the conversation.

  • Theo01
  • Theo01
  • OFFLINE
  • Posts: 16
  • Thanks: 0
  • Karma: 0
14 years 3 months ago #139345 by Theo01
Ok, I got it working. :)

How can I check in PHP that the Joomla! version is 1.5 or higher?

Please Log in or Create an account to join the conversation.

  • Theo01
  • Theo01
  • OFFLINE
  • Posts: 16
  • Thanks: 0
  • Karma: 0
14 years 3 months ago #139346 by Theo01
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. :)

Please Log in or Create an account to join the conversation.

  • slabbi
  • slabbi
  • OFFLINE
  • Posts: 3709
  • Thanks: 250
  • Karma: 153
14 years 3 months ago #139356 by slabbi
Well, maybe I create a special language file for notifications.

This may work but it nothing more than a hack.

uddeIM & uddePF Development
CB Language Workgroup
CB 3rd Party Developer

Please Log in or Create an account to join the conversation.

  • Theo01
  • Theo01
  • OFFLINE
  • Posts: 16
  • Thanks: 0
  • Karma: 0
14 years 3 months ago #139357 by Theo01
First I thought of separate language files too, or maybe just variable declarations for the four texts in question within the language php files.

On the other hand, this may cause a lot of work for all the users who have customized their notification messages.
Evaluating the constants' values in php to make them variables works with the existing language file base without changes.

Please Log in or Create an account to join the conversation.

Moderators: beatnantslabbikrileon
Powered by Kunena Forum