egroupware_official/phpgwapi/inc/class.setup_translation.inc.php

125 lines
3.8 KiB
PHP
Raw Normal View History

2002-03-03 22:47:30 +01:00
<?php
/**************************************************************************\
2004-05-05 14:06:13 +02:00
* eGroupWare API - Translation class for phpgw lang files *
* This file written by Miles Lott <milosch@groupwhere.org> *
2002-03-03 22:47:30 +01:00
* and Dan Kuykendall <seek3r@phpgroupware.org> *
* Handles multi-language support using flat files *
* -------------------------------------------------------------------------*
2004-05-05 14:06:13 +02:00
* This library is part of the eGroupWare API *
* http://www.egroupware.org/api *
2002-03-03 22:47:30 +01:00
* ------------------------------------------------------------------------ *
* 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 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 *
\**************************************************************************/
/* $Id$ */
if (!defined('MAX_MESSAGE_ID_LENGTH'))
{
define('MAX_MESSAGE_ID_LENGTH',230);
}
2002-03-03 22:47:30 +01:00
class setup_translation
{
2004-03-23 17:34:23 +01:00
var $langarray = array();
2002-03-03 22:47:30 +01:00
/*!
@function setup_lang
@abstract constructor for the class, loads all phrases into langarray
@param $lang user lang variable (defaults to en)
*/
function setup_translation()
{
$ConfigLang = get_var('ConfigLang',Array('POST','COOKIE'));
2002-03-03 22:47:30 +01:00
if(!$ConfigLang)
{
$lang = 'en';
}
else
{
$lang = $ConfigLang;
}
$fn = '.' . SEP . 'lang' . SEP . 'phpgw_' . $lang . '.lang';
if (!file_exists($fn))
{
$fn = '.' . SEP . 'lang' . SEP . 'phpgw_en.lang';
}
if (file_exists($fn))
{
$fp = fopen($fn,'r');
while ($data = fgets($fp,8000))
{
// explode with "\t" and removing "\n" with str_replace, needed to work with mbstring.overload=7
2004-05-09 12:25:30 +02:00
list($message_id,,,$content) = explode("\t",$data);
$this->langarray[strtolower(trim($message_id))] = str_replace("\n",'',$content);
2002-03-03 22:47:30 +01:00
}
fclose($fp);
}
}
2002-03-03 22:47:30 +01:00
/*!
@function translate
@abstract Translate phrase to user selected lang
@param $key phrase to translate
@param $vars vars sent to lang function, passed to us
*/
function translate($key, $vars=False)
{
2004-03-23 17:34:23 +01:00
$ret = $key.'*';
$key = strtolower(trim($key));
if (isset($this->langarray[$key]))
2002-03-03 22:47:30 +01:00
{
2004-03-23 17:34:23 +01:00
$ret = $this->langarray[$key];
2002-03-03 22:47:30 +01:00
}
2004-03-23 17:34:23 +01:00
if (is_array($vars))
2002-03-03 22:47:30 +01:00
{
2004-03-23 17:34:23 +01:00
foreach($vars as $n => $var)
{
$ret = preg_replace( '/%'.($n+1).'/', $var, $ret );
}
2002-03-03 22:47:30 +01:00
}
return $ret;
}
// the following functions have been moved to phpgwapi/tanslation_sql
2002-03-03 22:47:30 +01:00
function setup_translation_sql()
2002-03-03 22:47:30 +01:00
{
if (!is_object($this->sql))
2002-03-03 22:47:30 +01:00
{
include_once(PHPGW_API_INC.'/class.translation_sql.inc.php');
$this->sql = new translation;
2002-03-03 22:47:30 +01:00
}
}
2002-03-03 22:47:30 +01:00
function get_langs($DEBUG=False)
{
$this->setup_translation_sql();
return $this->sql->get_langs($DEBUG);
2002-03-03 22:47:30 +01:00
}
function drop_langs($appname,$DEBUG=False)
{
$this->setup_translation_sql();
return $this->sql->drop_langs($appname,$DEBUG);
2002-03-03 22:47:30 +01:00
}
function add_langs($appname,$DEBUG=False,$force_langs=False)
2002-03-03 22:47:30 +01:00
{
$this->setup_translation_sql();
return $this->sql->add_langs($appname,$DEBUG,$force_langs);
2002-03-03 22:47:30 +01:00
}
}
?>