Skip to content
Snippets Groups Projects
Commit 833b3801 authored by Olav Morken's avatar Olav Morken
Browse files

Introduce new attribute translation function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2581 44740490-163a-0410-bde0-09ae8108e29a
parent 56543c4b
No related branches found
No related tags found
No related merge requests found
...@@ -295,6 +295,29 @@ class SimpleSAML_XHTML_Template { ...@@ -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. * Translate a tag into the current language, with a fallback to english.
* *
......
...@@ -137,10 +137,7 @@ function present_attributes($t, $attributes, $nameParent) { ...@@ -137,10 +137,7 @@ function present_attributes($t, $attributes, $nameParent) {
foreach ($attributes as $name => $value) { foreach ($attributes as $name => $value) {
$nameraw = $name; $nameraw = $name;
$nameTag = '{attributes:attribute_' . $parentStr . str_replace(":", "_", strtolower($name) ) . '}'; $name = $t->getAttributeTranslation($nameraw);
if ($t->getTag($nameTag) !== NULL) {
$name = $t->t($nameTag);
}
if (preg_match('/^child_/', $nameraw)) { if (preg_match('/^child_/', $nameraw)) {
// Insert child table // Insert child table
......
...@@ -99,7 +99,7 @@ TRSTART; ...@@ -99,7 +99,7 @@ TRSTART;
if (isset($this->data['attribute_' . htmlspecialchars(strtolower($name)) ])) { if (isset($this->data['attribute_' . htmlspecialchars(strtolower($name)) ])) {
$name = $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) { if (sizeof($value) > 1) {
echo "<li>" . htmlspecialchars($name) . ":\n<ul>\n"; echo "<li>" . htmlspecialchars($name) . ":\n<ul>\n";
foreach ($value AS $v) { foreach ($value AS $v) {
......
...@@ -62,11 +62,8 @@ function present_attributes($t, $attributes, $nameParent) { ...@@ -62,11 +62,8 @@ function present_attributes($t, $attributes, $nameParent) {
foreach ($attributes as $name => $value) { foreach ($attributes as $name => $value) {
$nameraw = $name; $nameraw = $name;
$nameTag = '{attributes:attribute_' . $parentStr . str_replace(":", "_", strtolower($name) ) . '}'; $name = $t->getAttributeTranslation($nameraw);
if ($t->getTag($nameTag) !== NULL) {
$name = $t->t($nameTag);
}
if (preg_match('/^child_/', $nameraw)) { if (preg_match('/^child_/', $nameraw)) {
$parentName = preg_replace('/^child_/', '', $nameraw); $parentName = preg_replace('/^child_/', '', $nameraw);
foreach($value AS $child) { foreach($value AS $child) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment