<?php

	/*
	*	Gekko - Open Source Web Development Framework
	*	------------------------------------------------------------------------
	*	Copyright (C) 2004-2005, J. Carlos Nieto <xiam@users.sourceforge.net>
	*	This program is Free Software.
	*
	*	@package	Gekko
	*	@subpackage	/lib
	*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
	*	@author		J. Carlos Nieto <xiam@users.sf.net>
	*	@version	CVS: $Id:$
	*	@link		http://www.gekkoware.org
	*/

	if (!defined("IN-GEKKO")) die("Get a life!");

	Class Lang {
		var $Lang = "";
		var $LangPath = "";
		function getLang() {
			return $this->Lang;
		}
		function Lang($Lang = null) {

			$Lang = preg_replace("/[^a-zA-Z\-]/", "", $Lang);

			$this->Lang = ($Lang) ? $Lang : GEKKO_LANG;
			$this->LangPath = GEKKO_ROOT."lang/".$this->Lang."/";

			// verifying language file existence
			if (!file_exists($this->LangPath)) {
				$this->Lang = GEKKO_DEFAULT_LANG;
				$this->LangPath = GEKKO_ROOT."lang/".$this->Lang."/";
				//trigger_error("Couldn't load language \"".$this->Lang."\"... aborted.", E_USER_ERROR);
			}

			// loading main language
			$this->mainLang("main.php");

			// loading core language files
			$mods = ModCore::GetModules();
			foreach ($mods as $module) {
				$path = GEKKO_ROOT."modules/$module/lang/".$this->Lang."/core.php";
				if (file_exists($path)) include_once ($path);
			}

		}
		function mainLang($file) {
			include_once $this->LangPath."$file";
		}
		function Load($module, $load = "main") {
			$path = GEKKO_ROOT."modules/{$module}/lang/{$this->Lang}/{$load}.php";
			if (file_exists($path)) include $path;
		}
		// set a language variable
		function Set($varname, $value) {
			$GLOBALS["L"][$varname] = $value;
		}
		// gets a language variable by its key
		function Get($varname) {
			return isset($GLOBALS["L"][$varname]) ? $GLOBALS["L"][$varname] : $varname;
		}
	}

	/*
	*	_l(String ID);
	*	Returns a language string specified by its $id
	*/
	function _l($id, $value = false) {
		return ($value !== false) ? Lang::Set($id, $value) : Lang::Get($id);
	}
	/*
		Alias for Lang::Load();
	*/
	function loadLang($module) {
		return $GLOBALS["Lang"]->Load($module);
	}
?>
