From be93c24defb54b161cf7f3f2761f0322b9eac4d2 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 24 Jan 2018 11:33:35 -0700 Subject: [PATCH] Make sure popup notifications are fully in recipient's language "Message from" and "Linked entries" were in sender's language --- api/src/Translation.php | 35 +++++++++++++++++++ .../inc/class.notifications_popup.inc.php | 4 +-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/api/src/Translation.php b/api/src/Translation.php index c7f9827114..770446ff8d 100644 --- a/api/src/Translation.php +++ b/api/src/Translation.php @@ -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) * diff --git a/notifications/inc/class.notifications_popup.inc.php b/notifications/inc/class.notifications_popup.inc.php index 6d45dd76ab..197f3e8871 100644 --- a/notifications/inc/class.notifications_popup.inc.php +++ b/notifications/inc/class.notifications_popup.inc.php @@ -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 = "
"; $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); }