<?php
$module["lang"]["name"]="Language Class";
$module["lang"]["ver"]="0.1.2";
/**
 * Project:   BeCast WebEngine - simple site engine
 * File:      /inc/lang.class.php
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @link http://www.becast.at
 * @copyright 2009-2025 becast.at
 * @author Bernhard Jaud <bernhard at becast dot at>
 * @package BcWe core
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version $Id: 8929a005669603f570c7f7df5153236c9a460e56 $
 */


class lang{
	var $langname=array('de'=>'Deutsch','en'=>'English');
	var $language;
	var $languagedir;
	var array $langdata;
	
	function __construct($languagedir='/languages/'){
		$this->languagedir = dirname(dirname(__FILE__)).'/languages/';
	}	

	function setlang($language): void
    {
		global $config;
		unset($this->language);
		unset($this->langdata);
		if(!$language || $language==''){
			$language=$config['lang'];
			if(!$language){
				$this->language='en';
			}else{
				$this->language=$language;
			}
		}else{
			$this->language=$language;	
		}
		require_once $this->languagedir.$this->language.'.lang.php';
		if (isset($lf)) {
			$this->langdata = $lf;
		}
	}
	
	function getlanguages(){
		$langdir = $this->languagedir;
		$langs = opendir($langdir);
		$i=0;
		while ($lang = readdir($langs)) {
		    if (preg_match('/^.*?\.lang.php$/', $lang)) {
				$langfile[$i]['short']=substr($lang,0,2);
				$langfile[$i]['name']=$this->langname[$langfile[$i]['short']];
				$i++;
			}
		}
		@closedir($langs);
		return($langfile);
	}
	
	function _($string){
		if(isset($this->langdata[$string])){
			return($this->langdata[$string]);
		}else{
			return($string);
		}
	}

}
?>
