Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/html/locale/localize.php
<?php

# ------------------------------------------------------------------------------
#
# Contains the php locale function
#
# ------------------------------------------------------------------------------
#
# Copyright (C) 2003 Christian Eheim and Alex Pachikov
#
# This file is part of TVEz (tvez.sourceforge.net).
#
# TVEz 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 2 of the License, or
# (at your option) any later version.
#
# TVEz 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 TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# ------------------------------------------------------------------------------
#
# Created on 12/07/2003 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/01/19 19:06:38 $
# $Revision: 1.2 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

################################################################################
# Get the browser language
################################################################################
function get_lang() {
	if (isset($_SESSION['tvezLang']))
		return $_SESSION['tvezLang'];
	else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
		return substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
	else
		return "en";
}

################################################################################
# Returns the localized string if it exists
# otherwise returns the key (english)
################################################################################
function localize_string($key,$vars=array()) {
	global $TRANSLATED_TEXT;
	if (isset($TRANSLATED_TEXT["$key"]) && $TRANSLATED_TEXT["$key"] != "")
		$ret = $TRANSLATED_TEXT["$key"];
	else
		$ret = $key;

	# Replace variables
    if (sizeof($vars) == 0)
        return($ret);
    if (sizeof($vars) == 1)
        $vars=array($vars);
    return(preg_replace("/==([0-9]*)==/e", "\$vars[(\$1-1)];", $ret));

/*
	if (sizeof($vars) > 1)
		$ret = preg_replace("/==([0-9]*)==/e", "\$vars[(\$1-1)]", $ret);
	elseif (sizeof($vars) == 1)
		$ret = preg_replace("/==([0-9]*)==/e", "\$vars", $ret);
	return $ret;
*/
}

################################################################################
# Return the translation
################################################################################
function get_translation($localeDir) {

	# Load the html character entity file
	$cent = file("$localeDir/html_char_entities.inc");
	$cent = implode(' ',$cent);
	$cent = "\$char_entities = array (".$cent.");";
	eval($cent);

	# Load the language file
	$MYLANG = get_lang();
	$dicFile = "$localeDir/languages/$MYLANG/dictionary.$MYLANG";
	if (! is_file($dicFile)) $dicFile = "$localeDir/languages/en/dictionary.en";
	$textlan = implode(' ',file($dicFile));
	$textlan = "\$TEXT = array (".$textlan.");";

	# Replace any spaecial character entities
	foreach ( $char_entities as $key => $value )
		$textlan = preg_replace("/$key/","$value",$textlan);

	eval($textlan);
	return $TEXT;
}

?>
Return current item: TVEz - Media Library