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

Configuration: Add getLocalizedString().

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2023 44740490-163a-0410-bde0-09ae8108e29a
parent 940a6778
No related branches found
No related tags found
No related merge requests found
...@@ -970,6 +970,48 @@ class SimpleSAML_Configuration { ...@@ -970,6 +970,48 @@ class SimpleSAML_Configuration {
return $default; return $default;
} }
/**
* Retrieve a string which may be localized into many languages.
*
* The default language returned is always 'en'.
* @param string $name The name of the option.
* @param mixed $default The default value. If no default is given, and the option isn't found, an exception will be thrown.
* @return array Associative array with language=>string pairs.
*/
public function getLocalizedString($name, $default = self::REQUIRED_OPTION) {
assert('is_string($name)');
$ret = $this->getValue($name, $default);
if($ret === $default) {
/* The option wasn't found, or it matches the default value. In any case, return
* this value.
*/
return $ret;
}
$loc = $this->location . '[' . var_export($name, TRUE) . ']';
if (is_string($ret)) {
$ret = array('en' => $ret,);
}
if (!is_array($ret)) {
throw new Exception($loc . ': Must be an array or a string.');
}
foreach ($ret as $k => $v) {
if (!is_string($k)) {
throw new Exception($loc . ': Invalid language code: ' . var_export($k, TRUE));
}
if (!is_string($v)) {
throw new Exception($loc . '[' . var_export($v, TRUE) . ']: Must be a string.');
}
}
return $ret;
}
} }
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment