From 833b380195b32a101cdcfbac31d8585fe931797e Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 21 Oct 2010 11:20:05 +0000 Subject: [PATCH] Introduce new attribute translation function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2581 44740490-163a-0410-bde0-09ae8108e29a --- lib/SimpleSAML/XHTML/Template.php | 23 +++++++++++++++++++ modules/consent/templates/consentform.php | 5 +--- .../consentAdmin/templates/consentadmin.php | 2 +- templates/status.php | 7 ++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index 54674a59a..e92684813 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -295,6 +295,29 @@ class SimpleSAML_XHTML_Template { } + /** + * Translate a attribute name. + * + * @param string $name The attribute name. + * @return string The translated attribute name, or the original attribute name if no translation was found. + */ + public function getAttributeTranslation($name) { + + /* Normalize attribute name. */ + $normName = strtolower($name); + $normName = str_replace(":", "_", $normName); + + /* Search the default attribute dictionary. */ + $dict = $this->getDictionary('attributes'); + if (array_key_exists('attribute_' . $normName, $dict)) { + return $this->getTranslation($dict['attribute_' . $normName]); + } + + /* No translations found. */ + return $name; + } + + /** * Translate a tag into the current language, with a fallback to english. * diff --git a/modules/consent/templates/consentform.php b/modules/consent/templates/consentform.php index d023eed33..3b737f81b 100644 --- a/modules/consent/templates/consentform.php +++ b/modules/consent/templates/consentform.php @@ -137,10 +137,7 @@ function present_attributes($t, $attributes, $nameParent) { foreach ($attributes as $name => $value) { $nameraw = $name; - $nameTag = '{attributes:attribute_' . $parentStr . str_replace(":", "_", strtolower($name) ) . '}'; - if ($t->getTag($nameTag) !== NULL) { - $name = $t->t($nameTag); - } + $name = $t->getAttributeTranslation($nameraw); if (preg_match('/^child_/', $nameraw)) { // Insert child table diff --git a/modules/consentAdmin/templates/consentadmin.php b/modules/consentAdmin/templates/consentadmin.php index ae97cdf7d..446b94e06 100755 --- a/modules/consentAdmin/templates/consentadmin.php +++ b/modules/consentAdmin/templates/consentadmin.php @@ -99,7 +99,7 @@ TRSTART; if (isset($this->data['attribute_' . htmlspecialchars(strtolower($name)) ])) { $name = $this->data['attribute_' . htmlspecialchars(strtolower($name))]; } - $name = $this->t('attribute_'.strtolower($name)); // translate + $name = $this->getAttributeTranslation($name); // translate if (sizeof($value) > 1) { echo "<li>" . htmlspecialchars($name) . ":\n<ul>\n"; foreach ($value AS $v) { diff --git a/templates/status.php b/templates/status.php index 9c93364b1..faa37875e 100644 --- a/templates/status.php +++ b/templates/status.php @@ -62,11 +62,8 @@ function present_attributes($t, $attributes, $nameParent) { foreach ($attributes as $name => $value) { $nameraw = $name; - $nameTag = '{attributes:attribute_' . $parentStr . str_replace(":", "_", strtolower($name) ) . '}'; - if ($t->getTag($nameTag) !== NULL) { - $name = $t->t($nameTag); - } - + $name = $t->getAttributeTranslation($nameraw); + if (preg_match('/^child_/', $nameraw)) { $parentName = preg_replace('/^child_/', '', $nameraw); foreach($value AS $child) { -- GitLab