Make sure popup notifications are fully in recipient's language

"Message from" and "Linked entries" were in sender's language
This commit is contained in:
nathangray 2018-01-24 11:33:35 -07:00
parent da2291be12
commit be93c24def
2 changed files with 37 additions and 2 deletions

View File

@ -258,6 +258,41 @@ class Translation
return $ret;
}
/**
* Translates a phrase according to the given user's language preference,
* which may be different from the current user.
*
* @param int $account_id
* @param string $message
* @param array $vars =null vars to replace the placeholders, or null for none
*/
static function translate_as($account_id, $message, $vars=null)
{
if(!is_numeric($account_id))
{
return static::translate($message, $vars);
}
$preferences = new Preferences($account_id);
$prefs = $preferences->read();
if($prefs['common']['lang'] != $GLOBALS['egw_info']['user']['preferences']['common']['lang'])
{
$old_lang = self::$userlang;
$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $prefs['common']['lang'];
$apps = array_keys(self::$loaded_apps);
self::init(true);
self::add_app($apps);
}
$phrase = static::translate($message, $vars);
if($old_lang)
{
$GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $old_lang;
self::init(true);
self::add_app($apps);
}
return $phrase;
}
/**
* Adds translations for (multiple) application(s)
*

View File

@ -172,7 +172,7 @@ class notifications_popup implements notifications_iface {
}
if(count($rendered_links) > 0) {
return Api\Html::hr().Api\Html::bold(lang('Linked entries:')).$newline.implode($newline,$rendered_links);
return Api\Html::hr().Api\Html::bold(Api\Translation::translate_as($this->recipient->account_id,'Linked entries:')).$newline.implode($newline,$rendered_links);
}
}
@ -210,7 +210,7 @@ class notifications_popup implements notifications_iface {
$newline = "<br />";
$sender = $this->sender->account_fullname ? $this->sender->account_fullname : $this->sender_account_email;
$infos[] = lang('Message from').': '.$sender;
$infos[] = Api\Translation::translate_as($this->recipient->account_id, 'Message from').': '.$sender;
if(!empty($_subject)) { $infos[] = Api\Html::bold($_subject); }
return implode($newline,$infos);
}