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

Template: add getTranslation()-method.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@750 44740490-163a-0410-bde0-09ae8108e29a
parent 422f8b34
No related branches found
No related tags found
No related merge requests found
...@@ -206,6 +206,44 @@ class SimpleSAML_XHTML_Template { ...@@ -206,6 +206,44 @@ class SimpleSAML_XHTML_Template {
} }
/**
* Retrieve the preferred translation of a given text.
*
* @param $translations The translations, as an associative array with language => text mappings.
* @return The preferred translation.
*/
public function getTranslation($translations) {
assert('is_array($translations)');
/* Look up translation of tag in the selected language. */
$selected_language = $this->getLanguage();
if (array_key_exists($selected_language, $translations)) {
return $translations[$selected_language];
}
/* Look up translation of tag in the default language. */
$default_language = $this->getDefaultLanguage();
if(array_key_exists($default_language, $translations)) {
return $translations[$default_language];
}
/* Look up translation of tag in the base language. */
$base_language = $this->getBaseLanguage();
if(array_key_exists($base_language, $translations)) {
return $translations[$base_language];
}
/* Pick the first translation available. */
if(count($translations) > 0) {
$languages = array_keys($translations);
return $translations[$languages[0]];
}
/* We don't have anything to return. */
throw new Exception('Nothing to return from translation.');
}
/** /**
* Include text in the current language. * Include text in the current language.
* *
......
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