From f295ac5909944732a933a0c2c406cca7ad8a3951 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Fri, 5 Feb 2016 14:54:25 +0100
Subject: [PATCH] Add a method SimpleSAML_XHTML_Template::getTranslator() to
 retrieve the SimpleSAML\Locale\Translate instance local to the template, and
 use it to fix a bug in a template of the consent module.

---
 lib/SimpleSAML/XHTML/Template.php         | 18 ++++++++++++++++++
 modules/consent/templates/consentform.php |  4 +++-
 modules/consentAdmin/www/consentAdmin.php |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index c08017e58..a03dab446 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -11,6 +11,13 @@ class SimpleSAML_XHTML_Template
 {
     public $data = null;
 
+    /**
+     * A translator instance configured to work with this template.
+     *
+     * @var \SimpleSAML\Locale\Translate
+     */
+    private $translator;
+
     private $configuration = null;
     private $template = 'default.php';
 
@@ -31,6 +38,17 @@ class SimpleSAML_XHTML_Template
     }
 
 
+    /**
+     * Return the internal translator object used by this template.
+     *
+     * @return \SimpleSAML\Locale\Translate The translator that will be used with this template.
+     */
+    public function getTranslator()
+    {
+        return $this->translator;
+    }
+
+
     /**
      * @deprecated This method will be removed in SSP 2.0. Please use
      * SimpleSAML\Locale\Translate::getPreferredTranslation() instead.
diff --git a/modules/consent/templates/consentform.php b/modules/consent/templates/consentform.php
index 198dd8d72..cb6eb4ff6 100644
--- a/modules/consent/templates/consentform.php
+++ b/modules/consent/templates/consentform.php
@@ -139,6 +139,8 @@ if ($this->data['sppp'] !== false) {
  */
 function present_attributes($t, $attributes, $nameParent)
 {
+    $translator = $t->getTranslator();
+
     $alternate = array('odd', 'even');
     $i = 0;
     $summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"';
@@ -155,7 +157,7 @@ function present_attributes($t, $attributes, $nameParent)
 
     foreach ($attributes as $name => $value) {
         $nameraw = $name;
-        $name = $t->getAttributeTranslation($parentStr . $nameraw);
+        $name = $translator->getAttributeTranslation($parentStr . $nameraw);
 
         if (preg_match('/^child_/', $nameraw)) {
             // insert child table
diff --git a/modules/consentAdmin/www/consentAdmin.php b/modules/consentAdmin/www/consentAdmin.php
index 5a9037e12..a6b3df9a2 100644
--- a/modules/consentAdmin/www/consentAdmin.php
+++ b/modules/consentAdmin/www/consentAdmin.php
@@ -205,7 +205,7 @@ $template_sp_content = array();
 
 // Init template
 $template = new SimpleSAML_XHTML_Template($config, 'consentAdmin:consentadmin.php', 'consentAdmin:consentadmin');
-$translator = new \SimpleSAML\Locale\Translate($config, 'consentAdmin:consentadmin');
+$translator = $template->getTranslator();
 $sp_empty_name = $translator->getTag('sp_empty_name');
 $sp_empty_description = $translator->getTag('sp_empty_description');
 
-- 
GitLab