diff --git a/config-templates/config.php b/config-templates/config.php index aa11e1f4f37d0c9f68bc3b7273fdc7f73c36acb1..923e0146cc2c89a1c37751490b14e8faa2109753 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -423,9 +423,9 @@ $config = array( 'language.cookie.lifetime' => (60 * 60 * 24 * 900), /** - * Custom getLanguage function called from SimpleSAML_Locale_Language::getLanguage(). + * Custom getLanguage function called from SimpleSAML\Locale\Language::getLanguage(). * Function should return language code of one of the available languages or NULL. - * See SimpleSAML_Locale_Language::getLanguage() source code for more info. + * See SimpleSAML\Locale\Language::getLanguage() source code for more info. * * This option can be used to implement a custom function for determining * the default language for the user. diff --git a/lib/SimpleSAML/Locale/Language.php b/lib/SimpleSAML/Locale/Language.php index d7b830814093ea2dba58d9352aaf1b008d68a24f..059d562d1eb738c30dc2f3ae162ab26138061b00 100644 --- a/lib/SimpleSAML/Locale/Language.php +++ b/lib/SimpleSAML/Locale/Language.php @@ -1,12 +1,16 @@ <?php /** - * A minimalistic XHTML PHP based template system implemented for simpleSAMLphp. + * Choosing the language to localize to for our minimalistic XHTML PHP based template system. * * @author Andreas Ă…kre Solberg, UNINETT AS. <andreas.solberg@uninett.no> - * @package simpleSAMLphp + * @author Hanne Moa, UNINETT AS. <hanne.moa@uninett.no> + * @package SimpleSAMLphp */ -class SimpleSAML_Locale_Language { + +namespace SimpleSAML\Locale; + +class Language { /** * This is the default language map. It is used to map languages codes from the user agent to @@ -32,7 +36,7 @@ class SimpleSAML_Locale_Language { * @param $configuration Configuration object * @param $defaultDictionary The default dictionary where tags will come from. */ - function __construct(SimpleSAML_Configuration $configuration) { + function __construct(\SimpleSAML_Configuration $configuration) { $this->configuration = $configuration; $this->availableLanguages = $this->configuration->getArray('language.available', array('en')); @@ -55,7 +59,7 @@ class SimpleSAML_Locale_Language { if (in_array($language, $this->availableLanguages, TRUE)) { $this->language = $language; if ($setLanguageCookie === TRUE) { - SimpleSAML_Locale_Language::setLanguageCookie($language); + Language::setLanguageCookie($language); } } } @@ -85,7 +89,7 @@ class SimpleSAML_Locale_Language { } // Language is provided in a stored COOKIE - $languageCookie = SimpleSAML_Locale_Language::getLanguageCookie(); + $languageCookie = Language::getLanguageCookie(); if ($languageCookie !== NULL) { $this->language = $languageCookie; return $languageCookie; @@ -109,7 +113,7 @@ class SimpleSAML_Locale_Language { * languages in the header were available. */ private function getHTTPLanguage() { - $languageScore = SimpleSAML_Utilities::getAcceptLanguage(); + $languageScore = \SimpleSAML_Utilities::getAcceptLanguage(); /* For now we only use the default language map. We may use a configurable language map * in the future. @@ -185,7 +189,7 @@ class SimpleSAML_Locale_Language { * @return string|NULL The language, or NULL if unset. */ public static function getLanguageCookie() { - $config = SimpleSAML_Configuration::getInstance(); + $config = \SimpleSAML_Configuration::getInstance(); $availableLanguages = $config->getArray('language.available', array('en')); $name = $config->getString('language.cookie.name', 'language'); @@ -209,7 +213,7 @@ class SimpleSAML_Locale_Language { assert('is_string($language)'); $language = strtolower($language); - $config = SimpleSAML_Configuration::getInstance(); + $config = \SimpleSAML_Configuration::getInstance(); $availableLanguages = $config->getArray('language.available', array('en')); if (!in_array($language, $availableLanguages, TRUE) || headers_sent()) { @@ -224,7 +228,7 @@ class SimpleSAML_Locale_Language { 'httponly' => FALSE, ); - SimpleSAML_Utilities::setCookie($name, $language, $params, FALSE); + \SimpleSAML_Utilities::setCookie($name, $language, $params, FALSE); } } diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php index a6e57b43623e0ccd7b0f91ff356cd8ef7b83f188..e16300542c1155a73d8d43d2d1885e1109f98c05 100644 --- a/lib/SimpleSAML/Locale/Translate.php +++ b/lib/SimpleSAML/Locale/Translate.php @@ -1,12 +1,16 @@ <?php /** - * A minimalistic XHTML PHP based template system implemented for simpleSAMLphp. + * The translation-relevant bits from our original minimalistic XHTML PHP based template system. * * @author Andreas Ă…kre Solberg, UNINETT AS. <andreas.solberg@uninett.no> - * @package simpleSAMLphp + * @author Hanne Moa, UNINETT AS. <hanne.moa@uninett.no> + * @package SimpleSAMLphp */ -class SimpleSAML_Locale_Translate { + +namespace SimpleSAML\Locale; + +class Translate { private $configuration = null; @@ -31,15 +35,15 @@ class SimpleSAML_Locale_Translate { * @param $configuration Configuration object * @param $defaultDictionary The default dictionary where tags will come from. */ - function __construct(SimpleSAML_Configuration $configuration, $defaultDictionary = NULL) { + function __construct(\SimpleSAML_Configuration $configuration, $defaultDictionary = NULL) { $this->configuration = $configuration; - $this->language = new SimpleSAML_Locale_Language($configuration); + $this->language = new Language($configuration); if($defaultDictionary !== NULL && substr($defaultDictionary, -4) === '.php') { /* For backwards compatibility - print warning. */ $backtrace = debug_backtrace(); $where = $backtrace[0]['file'] . ':' . $backtrace[0]['line']; - SimpleSAML_Logger::warning('Deprecated use of new SimpleSAML_Locale_Translate(...) at ' . $where . + \SimpleSAML_Logger::warning('Deprecated use of new SimpleSAML\Locale\Translate(...) at ' . $where . '. The last parameter is now a dictionary name, which should not end in ".php".'); $this->defaultDictionary = substr($defaultDictionary, 0, -4); @@ -66,7 +70,7 @@ class SimpleSAML_Locale_Translate { if($sepPos !== FALSE) { $module = substr($name, 0, $sepPos); $fileName = substr($name, $sepPos + 1); - $dictDir = SimpleSAML_Module::getModuleDir($module) . '/dictionaries/'; + $dictDir = \SimpleSAML_Module::getModuleDir($module) . '/dictionaries/'; } else { $dictDir = $this->configuration->getPathValue('dictionarydir', 'dictionaries/'); $fileName = $name; @@ -212,12 +216,12 @@ class SimpleSAML_Locale_Translate { /* Old style call to t(...). Print warning to log. */ $backtrace = debug_backtrace(); $where = $backtrace[0]['file'] . ':' . $backtrace[0]['line']; - SimpleSAML_Logger::warning('Deprecated use of SimpleSAML_Template::t(...) at ' . $where . + \SimpleSAML_Logger::warning('Deprecated use of SimpleSAML_Template::t(...) at ' . $where . '. Please update the code to use the new style of parameters.'); /* For backwards compatibility. */ if(!$replacements && $this->getTag($tag) === NULL) { - SimpleSAML_Logger::warning('Code which uses $fallbackdefault === FALSE shouls be' . + \SimpleSAML_Logger::warning('Code which uses $fallbackdefault === FALSE shouls be' . ' updated to use the getTag-method instead.'); return NULL; } @@ -231,7 +235,7 @@ class SimpleSAML_Locale_Translate { $tagData = $this->getTag($tag); if($tagData === NULL) { /* Tag not found. */ - SimpleSAML_Logger::info('Template: Looking up [' . $tag . ']: not translated at all.'); + \SimpleSAML_Logger::info('Template: Looking up [' . $tag . ']: not translated at all.'); return $this->t_not_translated($tag, $fallbackdefault); } } @@ -280,7 +284,7 @@ class SimpleSAML_Locale_Translate { throw new Exception("Inline translation should be string or array. Is " . gettype($translation) . " now!"); } - SimpleSAML_Logger::debug('Template: Adding inline language translation for tag [' . $tag . ']'); + \SimpleSAML_Logger::debug('Template: Adding inline language translation for tag [' . $tag . ']'); $this->langtext[$tag] = $translation; } @@ -304,7 +308,7 @@ class SimpleSAML_Locale_Translate { $lang = $this->readDictionaryFile($filebase . $file); - SimpleSAML_Logger::debug('Template: Merging language array. Loading [' . $file . ']'); + \SimpleSAML_Logger::debug('Template: Merging language array. Loading [' . $file . ']'); $this->langtext = array_merge($this->langtext, $lang); } @@ -323,7 +327,7 @@ class SimpleSAML_Locale_Translate { $lang = json_decode($fileContent, TRUE); if (empty($lang)) { - SimpleSAML_Logger::error('Invalid dictionary definition file [' . $definitionFile . ']'); + \SimpleSAML_Logger::error('Invalid dictionary definition file [' . $definitionFile . ']'); return array(); } @@ -369,7 +373,7 @@ class SimpleSAML_Locale_Translate { private function readDictionaryFile($filename) { assert('is_string($filename)'); - SimpleSAML_Logger::debug('Template: Reading [' . $filename . ']'); + \SimpleSAML_Logger::debug('Template: Reading [' . $filename . ']'); $jsonFile = $filename . '.definition.json'; if (file_exists($jsonFile)) { @@ -382,7 +386,7 @@ class SimpleSAML_Locale_Translate { return $this->readDictionaryPHP($filename); } - SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filename . ']'); + \SimpleSAML_Logger::error($_SERVER['PHP_SELF'].' - Template: Could not find template file [' . $this->template . '] at [' . $filename . ']'); return array(); } diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index afe8e8e9fb0cacbf173145b80d3381cbf95a21c6..dd21f236e80a9acbc36c7c1bf18421684823d5fe 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -25,7 +25,7 @@ class SimpleSAML_XHTML_Template { $this->configuration = $configuration; $this->template = $template; $this->data['baseurlpath'] = $this->configuration->getBaseURL(); - $this->translator = new SimpleSAML_Locale_Translate($configuration, $defaultDictionary = NULL); + $this->translator = new SimpleSAML\Locale\Translate($configuration, $defaultDictionary = NULL); } /** @@ -42,7 +42,7 @@ class SimpleSAML_XHTML_Template { } /** - * Wrap Translate->getTranslation + * @deprecated This method will be removed in SSP 2.0. Please use SimpleSAML\Locale\Translate::getTranslation() instead. */ public function getTranslation($translations) { return $this->translator->getTranslation($translations); diff --git a/modules/core/lib/Auth/Process/LanguageAdaptor.php b/modules/core/lib/Auth/Process/LanguageAdaptor.php index 2084a229465eb06cd5d46f2f97272d3b4b79512a..cbc9478e2beac57fd980f0ecb0c8644a660a0952 100644 --- a/modules/core/lib/Auth/Process/LanguageAdaptor.php +++ b/modules/core/lib/Auth/Process/LanguageAdaptor.php @@ -44,7 +44,7 @@ class sspmod_core_Auth_Process_LanguageAdaptor extends SimpleSAML_Auth_Processin if (array_key_exists($this->langattr, $attributes)) $attrlang = $attributes[$this->langattr][0]; - $lang = SimpleSAML_Locale_Language::getLanguageCookie(); + $lang = SimpleSAML\Locale\Language::getLanguageCookie(); if (isset($attrlang)) @@ -55,7 +55,7 @@ class sspmod_core_Auth_Process_LanguageAdaptor extends SimpleSAML_Auth_Processin if (isset($attrlang) && !isset($lang)) { // Language set in attribute but not in cookie - update cookie - SimpleSAML_Locale_Language::setLanguageCookie($attrlang); + SimpleSAML\Locale\Language::setLanguageCookie($attrlang); } elseif (!isset($attrlang) && isset($lang)) { // Language set in cookie, but not in attribute. Update attribute $request['Attributes'][$this->langattr] = array($lang);