<?php
/* $Id: date_lang.inc.php,v 1.2 2003/11/13 14:21:40 leyeti Exp $ */

if (!defined("INCLUDE_LANG_DICT")) {
		   define("INCLUDE_LANG_DICT",1);
	}
else return;

/*
// =====================================================
// auto assign the language file into the smarty
// context, also assign some additional files
// which are in each page (navigation and footer...)
// RETURNS ALL keys and values of Language file in Hash
// =====================================================
function setLocaledText($language, $tf) {
    global $smarty, $appconf, $hashmap;
    $language= ($language=="login") ? $appconf["def_language"] : trim($language);

    // allways do navigation translation
    $myvars2 = readLanguageFile($language, "_navi", "general");
    $smarty->assign($myvars2);

    // allways do footer translation
    $myvars3 = readLanguageFile($language, "_footer", "general");
    $smarty->assign($myvars3);

    // allways do common words (general) translation
    // do this not if the user is allready in general module
    // cause then another line would read the file (see below)
    if($tf != "general") {
	$myvars4 = readLanguageFile($language, "general", "general");
	$smarty->assign($myvars4);
    }

    $myvars = readLanguageFile($language, $tf);
    $smarty->assign($myvars);

    if(IsSet($myvars4)) $newlang = array_merge($myvars, $myvars2, $myvars3, $myvars4);
		else $newlang = array_merge($myvars, $myvars2, $myvars3);

    $hashmap = $newlang;
    return $newlang;
    // return array_merge($myvars, $myvars2, $myvars3);
}
*/
	
// =====================================================
// Parser for reading in the language file
// see the language development guide for
// details how to define the language file
// =====================================================
function readDateLanguageFile($language, $directory, $filename) {
    
	global $date_hashmap, $date_language;
	
	
	if (isset($date_hashmap) and $language == $date_language) {
        return $date_hashmap;
    }
	
	$GLOBALS["date_language"]=$language;

	/*if (	substr($directory,strlen($directory)-1,strlen($directory)-1) != "/" 
		||	substr($directory,strlen($directory)-1,strlen($directory)-1) != "\\"
		)$directory .="/";
	*/	
	$fn = $directory."/$filename.$language.lang";

    $fp = fopen ($fn, "r") or die ("<p>Language File: <b>$fn</b> not available");
    if($fp) {
	while (!feof ($fp)) {
	    $buffer = fgets($fp, 4096);
	    if(trim($buffer)!='') {
		$arr1 = split ("=", $buffer, 2);
		if(ereg("=",$buffer)) {
		    $key = trim($arr1[0]);
		    $val = trim($arr1[1]);
		    $keyold = trim($arr1[0]);
		    $hashtable["$key"]=$val;
		}
		else {
		    $val .= " " . trim($arr1[0]);
		    $hashtable["$keyold"]=$val;
		}
	    }
	}
    }
    fclose ($fp);
    return $hashtable;	
}

// =====================================================
// A function for parameter based strings
// You can pass the string (which you got most likely
// from the language file) and an array with parameters.
// Then the vars in the string will be replaced with
// the paramters in the array (see language dev. guide) 
// =====================================================
function getDateParmLang($string, $parmarray) {
    // add one empty array element at first position because of naming conventions
    // in detail: in your language file you start with <$1> and not <$0>
    array_unshift($parmarray, "");

    return preg_replace("/<\\$([0-9])>/e", '$parmarray[\1]', $string);
}
	
// 15-01-2002 12:21, rabol : <srabol@mail.tele.dk>
// function to get a string from the current language, 
// or a string telling you that the string is missing
function getDateLanguageString($string){
    global $date_hashmap, $date_language;


    if(!isset($date_hashmap[$string])) {
	$ret_string = "* " . $string . " * ";
		$filename = $_SESSION["date_lang"]["lang_dir"]."/missing.".$date_language.".lang";
	    $missing = "date -> ".$string;
	    if(file_exists($filename)) {
		$fp = fopen($filename,"rb");
		$content = fread($fp, filesize($filename));
		$pos = strpos($content,$missing);
		if($pos === false) {
		    fclose($fp);
		    $fp = fopen($filename,"a+");
		    fputs($fp,$missing."\n");
		    fclose($fp);
		}	 
	    } else {
		$fp = fopen($filename,"w+");
		fputs($fp,$missing."\n");
		fclose($fp);
	    }
    } else {
	$ret_string = $date_hashmap[$string];
    }
    return $ret_string;
}
?>
