class_Language.inc.php 6.01 KB
<?php
/**
 * @file	Language.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   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/>.
 * 
 */
class Language {

	private static $choosenLang;

	public static function getGeneralLinks($param_key, $param_link=null) {
		if($param_link) {
			return TreeLanguage::$GeneralLinks[$param_key][$param_link];
		} else if(array_key_exists($param_key, TreeLanguage::$GeneralLinks) && TreeLanguage::$GeneralLinks[$param_key]) {
			return TreeLanguage::$GeneralLinks[$param_key];
		} else {
			return  array('label' => $param_key, 	'image' => '');
		}
	}

	public static function getBCRightManagement($param_BasisClipboardname) {
		$var_BCLanguage = Language::getClassLinks($param_BasisClipboardname, 'RightManagement');
		if(array_key_exists('ReadKeys', $var_BCLanguage) && array_key_exists('WriteKeys', $var_BCLanguage)) {
			return $var_BCLanguage;
		} else {
			return Language::getClassLinks('BasisClipboard', 'RightManagement');
		}
	}



	/**
	 *	return the languge data
	 *
	 *	@param string param_class (@see TreeConfig::$ClassLinks[param_class])
	 *	@param string param_link (@see TreeConfig::$ClassLinks[param_class][$param_link])
	 *	@param string param_index (@see TreeConfig::$ClassLinks[param_class][$param_link][param_index])
	 */
	public static function getClassLinks($param_class, $param_link=null, $param_index = null) {

		//D::li('Language::getClassLinks('.$param_class.", $param_link=null, $param_index = null".')');
		$param_class = trim($param_class);
		$param_link = trim($param_link);
		$var_ClassCategoryArray = CONFIG::transformStringToArray($param_class, 'category');

		/**
		 * @if Klassename (evt. mit Kategorie bei BasisClipboard (dann BasisClipboard::Category))
		 */
		if(array_key_exists($param_class, TreeLanguage::$ClassLinks) && array_key_exists($param_link, TreeLanguage::$ClassLinks[$param_class]) && $param_link!=null) {
			if($param_index == null){
				return TreeLanguage::$ClassLinks[$param_class][$param_link];
				//				$var_return = TreeLanguage::$ClassLinks[$param_class][$param_link];
			}
			else{
				return TreeLanguage::$ClassLinks[$param_class][$param_link][$param_index];
				//				$var_return = TreeLanguage::$ClassLinks[$param_class][$param_link][$param_index];
			}
			/**
			 * @elseif wenn nicht kompletter Klasssenname gefunden wurde, dann ohne Category (falls vorhanden)
			 */
		} else if(array_key_exists($var_ClassCategoryArray[0], TreeLanguage::$ClassLinks) && array_key_exists($param_link, TreeLanguage::$ClassLinks[$var_ClassCategoryArray[0]]) && $param_link!=null) {
			if($param_index == null){
				//				return TreeLanguage::$ClassLinks[$var_ClassCategoryArray[0]][$param_link];
				return TreeLanguage::$ClassLinks[$var_ClassCategoryArray[0]][$param_link];
			}
			else{
				//				return TreeLanguage::$ClassLinks[$var_ClassCategoryArray[0]][$param_link][$param_index];
				return TreeLanguage::$ClassLinks[$var_ClassCategoryArray[0]][$param_link][$param_index];
			}

		}
		//		return false;
		return array('label' => $param_link);
	}

	public static function getService($param_index) {
		if(TreeLanguage::$GroupArray['Services'][$param_index]) {
			return TreeLanguage::$GroupArray['Services'][$param_index];
		} else {
			return $param_index;
		}
	}

	public static function getWord($param_word) {

		if(array_key_exists(trim($param_word), TreeLanguage::$Words)) {
			return TreeLanguage::$Words[trim($param_word)];
		} else {
			return $param_word;
		}
	}

	public static function getGroupLanguage($param_Group, $param_index) {
		if(array_key_exists($param_Group, TreeLanguage::$GroupArray) && array_key_exists($param_index, TreeLanguage::$GroupArray[$param_Group]) &&  TreeLanguage::$GroupArray[$param_Group][$param_index]) {
			return TreeLanguage::$GroupArray[$param_Group][$param_index];
		} else {
			return array('label' => $param_index);
		}
	}
	public static function getMessage($param_kind, $param_index) {
		if(TreeLanguage::$Lang_Message[$param_kind][$param_index]) {
			return TreeLanguage::$Lang_Message[$param_kind][$param_index];
		} else {
			return false;
		}
	}

	/**
	 * 	Function returns a XML Language Filename defined in class TreeLanguage.
	 *  If param_key doesn't exists in the array, the default Filename will be returned!
	 *
	 * 	@param String param_kind
	 *
	 *	@return String XML Language Filename
	 */
	public static function getLanguageFilename($param_key = false) {
		if(!$param_key){
			$param_key=TreeLanguage::$DefaultLanguage;
		}
		else if(!array_key_exists($param_key,TreeLanguage::$LanguageFilename)){
			Error::newError("Language","Language option ".$param_key." does not exist! Language is set to default -> ".TreeLanguage::$DefaultLanguage,"256");
			$param_key=TreeLanguage::$DefaultLanguage;
		}
		if(array_key_exists($param_key,TreeLanguage::$LanguageFilename)) {
			self::setISOLanguage($param_key);
			return TreeLanguage::$LanguageFilename[$param_key];
		}
	}
	private static function setISOLanguage($param_key) {
		self::$choosenLang = $param_key;
		$_GET[CONSTKindOf::LANG]=$param_key;
	}
	public static function getISOLanguage() {
		return self::$choosenLang;
	}
	public static function addISOLanguages(&$param_DOMDocument){
		foreach(TreeLanguage::$LanguageFilename as $key => $value){
			$DOMElement = $param_DOMDocument->createElement('ISO');
			$DOMElement->setAttribute('code',$key);
			$param_DOMDocument->documentElement->appendChild($DOMElement);
		}
	}
}
?>