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

Template: add support for dictionary names in tag names.

This patch makes it possible to write '{<dictionary>:<tag>}' as the tag
name. This will load the given dictionary and fetch the given tag from there.


git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@753 44740490-163a-0410-bde0-09ae8108e29a
parent ca63a255
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,13 @@ class SimpleSAML_XHTML_Template {
public $data = null;
/**
* Associative array of dictionaries.
*/
private $dictionaries = array();
/**
* Constructor
*
......@@ -187,22 +194,52 @@ class SimpleSAML_XHTML_Template {
}
/**
* Retrieve a dictionary.
*
* This function retrieves a dictionary with the given name.
*
* @param $name The name of the dictionary, as the filename in the dictionary directory,
* without the '.php'-ending.
* @return An associative array with the dictionary.
*/
private function getDictionary($name) {
assert('is_string($name)');
if(!array_key_exists($name, $this->dictionaries)) {
$dictDir = $this->configuration->getPathValue('dictionarydir');
$this->dictionaries[$name] = $this->readDictionaryFile($dictDir . $name . '.php');
}
return $this->dictionaries[$name];
}
/**
* Retrieve a tag.
*
* This function retrieves a tag as an array with language => string mappings.
*
* @param $tag The tag name.
* @param $tag The tag name. The tag name can also be on the form '{<dictionary>:<tag>}', to retrieve
* a tag from the specific dictionary.
* @return As associative array with language => string mappings, or NULL if the tag wasn't found.
*/
public function getTag($tag) {
assert('is_string($tag)');
if(!array_key_exists($tag, $this->langtext)) {
if(substr($tag, 0, 1) === '{' && preg_match('/^{(\w+?):(.*)}$/', $tag, $matches)) {
$dictionary = $matches[1];
$tag = $matches[2];
$dictionary = $this->getDictionary($dictionary);
} else {
$dictionary = $this->langtext;
}
if(!array_key_exists($tag, $dictionary)) {
return NULL;
}
return $this->langtext[$tag];
return $dictionary[$tag];
}
......
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