Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1859)
+++ branches/2.8.x/CHANGELOG	(revision 1860)
@@ -11,7 +11,9 @@
 ! = Update/Change
 ===============================================================================
 
-
+04 Feb-2013 Build 1860 Werner v.d.Decken(DarkViper)
++ added new translation classes (Translate/TranslationTable/TranslateAdaptorWbOldStyle) for easy handling of language files
+! initialize and activate class Translate in /framework/initialize.php
 11 Jan-2013 Build 1859 Dietmar Woellbrink (Luisehahne)
 # bugfix  mkdir(): Invalid argument if create acessfile
 11 Jan-2013 Build 1858 Dietmar Woellbrink (Luisehahne)
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1859)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1860)
@@ -51,5 +51,5 @@
 
 // check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
 if(!defined('VERSION')) define('VERSION', '2.8.3');
-if(!defined('REVISION')) define('REVISION', '1859');
+if(!defined('REVISION')) define('REVISION', '1860');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/framework/Translate.php
===================================================================
--- branches/2.8.x/wb/framework/Translate.php	(nonexistent)
+++ branches/2.8.x/wb/framework/Translate.php	(revision 1860)
@@ -0,0 +1,190 @@
+<?php
+
+/**
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Translate.php
+ *
+ * @category     Core
+ * @package      Core_Translation
+ * @author       Werner v.d.Decken <wkl@isteam.de>
+ * @copyright    Werner v.d.Decken <wkl@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      0.0.1
+ * @revision     $Revision$
+ * @link         $HeadURL$
+ * @lastmodified $Date$
+ * @since        File available since 12.01.2013
+ * @description
+ */
+class Translate {
+	
+//  @object hold the Singleton instance 
+	private static $_oInstance   = null;
+	
+	protected $_sAdaptor         = 'WbOldStyle';
+	protected $_sDefaultLanguage = 'en';
+	protected $_sUserLanguage    = 'en';
+	protected $_aAddons          = array();
+	protected $_aTranslations    = array();
+
+/** prevent class from public instancing and get an object to hold extensions */
+	protected function  __construct() {}
+/** prevent from cloning existing instance */
+	private function __clone() {}
+/**
+ * get a valid instance of this class
+ * @return object
+ */
+	static public function getInstance() {
+		if( is_null(self::$_oInstance) ) {
+            $c = __CLASS__;
+            self::$_oInstance = new $c;
+		}
+		return self::$_oInstance;
+	}
+/**
+ * Initialize the Translations
+ * @param string DefaultLanguage code ('de' || 'de_CH' || 'de_CH_uri')
+ * @param string UserLanguage code ('de' || 'de_CH' || 'de_CH_uri')
+ * @throws TranslationException
+ */
+	public function initialize($sDefaultLanguage, $sUserLanguage = '', $sAdaptor = 'WbOldStyle') 
+	{
+		if(!class_exists('TranslateAdaptor'.$sAdaptor)) {
+			throw new TranslationException('unable to load adaptor: '.$sAdaptor);
+		}
+		$this->_sAdaptor = $sAdaptor;
+		$this->_sDefaultLanguage = $sDefaultLanguage;
+		// if no user language is set then use default language
+		$this->_sUserLanguage = ($sUserLanguage == '' ? $sDefaultLanguage : $sUserLanguage);
+		$sPattern = '/^[a-z]{2,3}(?:(?:\_[a-z]{2})?(?:\_[a-z0-9]{2,4})?)$/siU';
+		// validate language codes
+		if(preg_match($sPattern, $this->_sDefaultLanguage) &&
+		   preg_match($sPattern, $this->_sUserLanguage))
+		{
+		// load core translations and activate it
+			$oTmp = new TranslationTable('', $this->_sDefaultLanguage, $this->_sUserLanguage);
+			$this->_aAddons['core'] = $oTmp->load($this->_sAdaptor);
+			$this->_aTranslations[0] = $this->_aAddons['core'];
+			if(sizeof($this->_aAddons['core']) == 0) {
+			// throw an exception for missing translations
+				throw new TranslationException('missing core translations');
+			}
+		}else {
+		// throw an exception for invalid or missing language codes
+			$sMsg = 'Invalid language codes: ['.$this->_sDefaultLanguage.'] ['.$this->_sUserLanguage.']';
+			throw new TranslationException($sMsg);
+		}
+	}
+/**
+ * Add new addon
+ * @param string Addon descriptor (i.e. 'modules\myAddon')
+ * @return bool 
+ */	
+	public function addAddon($sAddon)
+	{
+		if(!(strtolower($sAddon) == 'core' || $sAddon == '' || isset($this->_aAddons[$sAddon]))) {
+		// load requested addon translations if needed and possible
+			$oTmp = new TranslationTable($sAddon, $this->_sDefaultLanguage, $this->_sUserLanguage);
+			$this->_aAddons[$sAddon] = $oTmp->load($this->_sAdaptor);
+		}
+	}
+/**
+ * Activate Addon
+ * @param string Addon descriptor (i.e. 'modules\myAddon')
+ */	
+	public function enableAddon($sAddon)
+	{
+		if(!(strtolower($sAddon) == 'core' || $sAddon == '')) {
+			if(!isset($this->_aAddons[$sAddon])) {
+				$this->addAddon($sAddon);
+			}
+			$this->_aTranslations[1] = $this->_aAddons[$sAddon];
+		}
+		
+	}
+	
+	public function disableAddon()
+	{
+		if(isset($this->_aTranslations[1])) {
+			unset($this->_aTranslations[1]);
+		}
+	}
+	
+/**
+ * Is key available
+ * @param string Language key
+ * @return bool
+ */
+	public function __isset($sKey)
+	{
+		foreach($this->_aTranslations as $oAddon) {
+			if(isset($oAddon->$sKey)) {
+			// is true if at least one translation is found
+				return true;
+			}
+		}
+		return false;
+	}
+/**
+ * Get translation text
+ * @param string Language key
+ * @return string Translation text
+ */	
+	public function __get($sKey)
+	{
+		$sRetval = '';
+		foreach($this->_aTranslations as $oAddon) {
+			if(isset($oAddon->$sKey)) {
+			// search the last matching translation (Core -> Addon)
+				$sRetval = $oAddon->$sKey;
+			}
+		}
+		return $sRetval;
+	}
+/**
+ * Return complete table of translations
+ * @return array
+ * @deprecated for backward compatibility only. Will be removed shortly
+ */	
+	public function getLangArray()
+	{
+		$aTranslations = array();
+		foreach($this->_aTranslations as $aTranslation) {
+			$aTranslations = array_merge($aTranslations, $aTranslation);
+		}
+		return $aTranslations;
+	}
+	
+} // end of class Translate
+// //////////////////////////////////////////////////////////////////////////////////// //
+/**
+ * TranslationException
+ *
+ * @category     Core
+ * @package      Core_Translation
+ * @author       Werner v.d.Decken <wkl@isteam.de>
+ * @copyright    Werner v.d.Decken <wkl@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      2.9.0
+ * @revision     $Revision$
+ * @lastmodified $Date$
+ * @description  Exceptionhandler for the Translation class and depending classes
+ */
+class TranslationException extends AppException {}
\ No newline at end of file

Property changes on: branches/2.8.x/wb/framework/Translate.php
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Date Author Id Revision HeadURL
\ No newline at end of property
Index: branches/2.8.x/wb/framework/TranslationTable.php
===================================================================
--- branches/2.8.x/wb/framework/TranslationTable.php	(nonexistent)
+++ branches/2.8.x/wb/framework/TranslationTable.php	(revision 1860)
@@ -0,0 +1,121 @@
+<?php
+
+/**
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * TranslationTable.php
+ *
+ * @category     Core
+ * @package      Core_Translation
+ * @author       Werner v.d.Decken <wkl@isteam.de>
+ * @copyright    Werner v.d.Decken <wkl@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      0.0.1
+ * @revision     $Revision$
+ * @link         $HeadURL$
+ * @lastmodified $Date$
+ * @since        File available since 12.01.2013
+ */
+class TranslationTable {
+
+	private $_aTranslations = array();
+	private $_sSystemLang   = 'en';
+	private $_sDefaultLang  = 'en';
+	private $_sUserLang     = 'en';
+	private $_sAddon        = '';
+	
+/**
+ * Constructor
+ * @param string relative pathname of the Addon (i.e. '' || 'modules/myAddon/')
+ * @param string Default language code ( 2ALPHA[[_2ALPHA]_2*4ALNUM] )
+ * @param string User language code ( 2ALPHA[[_2ALPHA]_2*4ALNUM] )
+ */	
+	public function __construct($sAddon, $sDefaultLanguage, $sUserLanguage = '')
+	{
+		$this->_sDefaultLang = $sDefaultLanguage;
+		$this->_sUserLang = ($sUserLanguage == '' ? $sDefaultLanguage : $sUserLanguage);
+		$this->_sAddon = $sAddon;
+	}
+/**
+ * Load language definitions
+ * @return TranslationTable a valid translation table object
+ * @throws TranslationException
+ */	
+	public function load($sAdaptor)
+	{
+		$c = 'TranslateAdaptor'.$sAdaptor;
+		$oTmp = new $c($this->_sAddon);
+		// load default language first
+		if( ($aResult = $oTmp->loadLanguage($this->_sDefaultLang)) !== false ) {
+			$this->_aTranslations = $aResult;
+		}
+		if($this->_sUserLang != $this->_sDefaultLang) {
+		// load user language if its not equal default language
+			if( ($aResult = $oTmp->loadLanguage($this->_sUserLang)) !== false ) {
+				$this->_aTranslations = array_merge($this->_aTranslations, $aResult);
+			}
+		}
+		if(($this->_sSystemLang != $this->_sUserLang) && 
+		   ($this->_sSystemLang != $this->_sDefaultLang)) {
+		// load system language if its not already loaded
+			if( ($aResult = $oTmp->loadLanguage($this->_sSystemLang)) !== false ) {
+				$this->_aTranslations = array_merge($this->_aTranslations, $aResult);
+			}
+		}
+		if(sizeof($this->_aTranslations) == 0) {
+		// if absolutely no requested language found, simply get the first available 
+			$sFirstLanguage = $oTmp->findFirstLanguage();
+		// load first found language if its not already loaded
+			if( ($aResult = $oTmp->loadLanguage($sFirstLanguage)) !== false ) {
+				$this->_aTranslations = array_merge($this->_aTranslations, $aResult);
+			}
+		}
+		return $this;
+	}
+/**
+ * Is key available
+ * @param string Language key
+ * @return bool
+ */
+	public function __isset($sKey)
+	{
+		return isset($this->_aTranslations[$sKey]);
+	}
+/**
+ * Get translation text
+ * @param string Language key
+ * @return string Translation text
+ */	
+	public function __get($sKey)
+	{
+		if(isset($this->_aTranslations[$sKey])) {
+			return $this->_aTranslations[$sKey];
+		}else {
+			return '';
+		}
+	}
+/**
+ * returns the whoole translation array
+ * @return array
+ * @deprecated for backward compatibility only. Will be removed shortly
+ */	
+	public function getArray()
+	{
+		return $this->_aTranslations;
+	}
+} // end of class TranslationTable
\ No newline at end of file

Property changes on: branches/2.8.x/wb/framework/TranslationTable.php
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Date Author Id Revision HeadURL
\ No newline at end of property
Index: branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php
===================================================================
--- branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php	(nonexistent)
+++ branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php	(revision 1860)
@@ -0,0 +1,136 @@
+<?php
+
+/**
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * TranslationTable.php
+ *
+ * @category     Core
+ * @package      Core_Translation
+ * @author       Werner v.d.Decken <wkl@isteam.de>
+ * @copyright    Werner v.d.Decken <wkl@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      0.0.1
+ * @revision     $Revision$
+ * @link         $HeadURL$
+ * @lastmodified $Date$
+ * @since        File available since 12.01.2013
+ * @description  Loads translation table from old languagefiles before WB-2.9.0.
+ *               Can handle Languagecodes like 'de_DE_BAY' (2ALPHA_2ALPHA_2-4ALNUM)
+ */
+class TranslateAdaptorWbOldStyle {
+
+	protected $sAppPath   = '';
+	protected $sAddon     = '';
+	protected $aLangTable = array();
+	protected $sFilePath  = '';
+/**
+ * Constructor
+ * @param string descriptor of the Addon (i.e. '' || 'modules\myAddon'
+ */
+	public function __construct($sAddon = '')
+	{
+		$this->sAddon = $sAddon;
+		$this->sAppPath = dirname(dirname(__FILE__)).'/';
+		$this->sFilePath = $this->sAppPath
+		                 . trim(str_replace('\\', '/', $sAddon), '/').'/languages/';
+	}
+/**
+ * Load languagefile
+ * @param string $sLangCode
+ * @return array|bool an array of translations or FALSE on error
+ */
+	public function loadLanguage($sLangCode)
+	{
+		$aTranslations = array();
+		// sanitize the language code
+		$aLangCode = explode('_', preg_replace('/[^a-z0-9]/i', '_', strtolower($sLangCode)));
+		$sConcatedLang = '';
+		foreach($aLangCode as $sLang)
+		{ // iterate all segments of the language code
+			$sLangFile = '';
+			$sLang = strtolower($sLang);
+			// seek lowerchars file
+			if(is_readable($this->sFilePath.$sConcatedLang.$sLang.'.php')) {
+				$sLangFile = $this->sFilePath.$sConcatedLang.$sLang.'.php';
+			}else {
+				// seek upperchars file
+				$sLang = strtoupper($sLang);
+				if(is_readable($this->sFilePath.$sConcatedLang.$sLang.'.php')) {
+					$sLangFile = $this->sFilePath.$sConcatedLang.$sLang.'.php';
+				}
+			}
+			if($sLangFile) {
+			// import the fond file
+				$sConcatedLang .= $sLangFile.'_';
+				$aTmp = $this->_importArrays($sLangFile);
+				$aTranslations = array_merge($aTranslations, $aTmp);
+			}
+		}
+		return (sizeof($aTranslations) > 0 ? $aTranslations : false);
+	}
+/**
+ * Find first existing language
+ * @return string Code of first found language
+ */
+	public function findFirstLanguage()
+	{
+	// search for first available and readable language file
+		$sRetval = '';
+		if(is_readable($this->sFilePath)) {
+			$iterator = new DirectoryIterator($this->sFilePath);
+			foreach ($iterator as $oFileInfo) {
+				$sPattern = '/^[a-z0-9]{2}(?:(?:\_[a-z0-9]{2})?(?:\_[a-z0-9]{2,4})?)\.php/siU';
+				if(!preg_match($sPattern, $oFileInfo->getBasename())) { continue; }
+				if($oFileInfo->isReadable()) {
+					$sRetval = $oFileInfo->getBasename('.php');
+					break;
+				}
+			}
+		}
+		return $sRetval;
+	}
+/**
+ * Import language definitions into array
+ * @param string load language from filename
+ * @return array contains all found translations
+ */
+	private function _importArrays($sLanguageFile)
+	{
+		// include the file
+		include($sLanguageFile);
+		// get all available loaded vars of this method
+		$aAllVars = get_defined_vars();
+		$aLangSections = array();
+		$aLanguageTable = array();
+		foreach($aAllVars as $key=>$value) {
+		// extract the names of arrays from language file
+			if(is_array($value)) {
+				$aLangSections[] = $key;
+			}
+		}
+		foreach($aLangSections as $sSection) {
+		// walk through all arrays
+			foreach(${$sSection} as $key => $value) {
+			// and import all found translations
+				$aLanguageTable[$sSection.'_'.$key] = $value;
+			}
+		}
+		return $aLanguageTable;
+	}
+} // end of class TranslateAdaptorWbOldStyle

Property changes on: branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Date Author Id Revision HeadURL
\ No newline at end of property
