From 45759aa7ca452f0a926434ba8ae878d82f18c78b Mon Sep 17 00:00:00 2001 From: Andjelko Horvat <comel@vingd.com> Date: Tue, 6 Dec 2011 12:32:00 +0000 Subject: [PATCH] SimpleSAML_XHTML_Template::getLanguage(): add support for custom function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2996 44740490-163a-0410-bde0-09ae8108e29a --- config-templates/config.php | 12 ++++++++++++ lib/SimpleSAML/XHTML/Template.php | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/config-templates/config.php b/config-templates/config.php index 4ccf37c49..e5bc789bd 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -251,6 +251,18 @@ $config = array ( 'language.rtl' => array('ar','dv','fa','ur','he'), 'language.default' => 'en', + /** + * Custom getLanguage function called from SimpleSAML_XHTML_Template::getLanguage(). + * Function should return language code of one of the available languages or NULL. + * See SimpleSAML_XHTML_Template::getLanguage() source code for more info. + * + * This option can be used to implement a custom function for determining + * the default language for the user. + * + * Example: + * 'language.get_language_function' => array('sspmod_example_Template', 'getLanguage'), + */ + /* * Extra dictionary for attribute names. * This can be used to define local attributes. diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index f5245596c..e9da55d21 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -97,6 +97,16 @@ class SimpleSAML_XHTML_Template { return $this->language; } + // Run custom getLanguage function if defined + $customFunction = $this->configuration->getArray('language.get_language_function', NULL); + if (isset($customFunction)) { + assert('is_callable($customFunction)'); + $customLanguage = call_user_func($customFunction, $this); + if ($customLanguage !== NULL && $customLanguage !== FALSE) { + return $customLanguage; + } + } + // Language is provided in a stored COOKIE $languageCookie = SimpleSAML_XHTML_Template::getLanguageCookie(); if ($languageCookie !== NULL && in_array($languageCookie, $this->availableLanguages, TRUE)) { -- GitLab