2001-06-15 23:23:46 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - Translation class for phpgw lang files *
|
|
|
|
* This file written by Miles Lott <milosch@phpgroupware.org> *
|
|
|
|
* Handles multi-language support using flat files *
|
|
|
|
* -------------------------------------------------------------------------*
|
|
|
|
* This library is part of the phpGroupWare API *
|
|
|
|
* http://www.phpgroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* 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$ */
|
|
|
|
|
|
|
|
class translation
|
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
var $lang; // Currently loaded translations
|
|
|
|
var $loaded = False;
|
|
|
|
var $all_loaded = False;
|
2002-05-31 10:29:19 +02:00
|
|
|
var $translator_helper = '*';
|
2002-05-20 02:45:52 +02:00
|
|
|
|
|
|
|
function translation()
|
|
|
|
{
|
|
|
|
if(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) &&
|
|
|
|
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
|
|
|
|
{
|
|
|
|
$this->userlang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->currentapp = $GLOBALS['phpgw_info']['flags']['currentapp'];
|
|
|
|
}
|
2001-06-15 23:23:46 +02: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
|
|
|
|
*/
|
2002-05-20 02:45:52 +02:00
|
|
|
function translate($key,$vars=False)
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
if(!$vars)
|
2001-09-28 23:32:44 +02:00
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
$vars = array();
|
2001-09-28 23:32:44 +02:00
|
|
|
}
|
2002-05-20 02:45:52 +02:00
|
|
|
$ret = $key;
|
|
|
|
$_key = strtolower($key);
|
2001-06-15 23:23:46 +02:00
|
|
|
|
2002-05-20 02:45:52 +02:00
|
|
|
if(!@isset($this->lang[$_key]) && !$this->loaded)
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
$this->load_langs();
|
2001-06-15 23:23:46 +02:00
|
|
|
}
|
2002-05-20 02:45:52 +02:00
|
|
|
if(!@isset($this->lang[$_key]) &&
|
2002-05-21 05:03:22 +02:00
|
|
|
($this->currentapp == 'admin' || $this->currentapp == 'preferences' || $this->currentapp == 'home') &&
|
2002-05-20 02:45:52 +02:00
|
|
|
!$this->all_loaded
|
|
|
|
)
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
$this->load_langs(True);
|
2001-06-15 23:23:46 +02:00
|
|
|
}
|
|
|
|
|
2002-05-31 10:29:19 +02:00
|
|
|
$ret = @isset($this->lang[$_key]) ? $this->lang[$_key] : $key . $this->translator_helper;
|
2001-06-15 23:23:46 +02:00
|
|
|
|
|
|
|
$ndx = 1;
|
2002-05-20 02:45:52 +02:00
|
|
|
while(list($key,$val) = each($vars))
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
|
|
|
$ret = preg_replace( "/%$ndx/", $val, $ret );
|
|
|
|
++$ndx;
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2002-05-20 02:45:52 +02:00
|
|
|
function load_langs($all=False)
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
2002-05-20 03:11:27 +02:00
|
|
|
if(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) &&
|
|
|
|
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
|
|
|
|
{
|
|
|
|
$this->userlang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
|
|
|
|
}
|
|
|
|
|
2002-05-20 02:45:52 +02:00
|
|
|
if($all)
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
@reset($GLOBALS['phpgw_info']['user']['apps']);
|
|
|
|
while(list(,$appname) = @each($GLOBALS['phpgw_info']['user']['apps']))
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
$this->add_app($appname['name']);
|
2001-06-15 23:23:46 +02:00
|
|
|
}
|
2002-05-20 02:45:52 +02:00
|
|
|
$this->all_loaded = True;
|
2001-06-15 23:23:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-20 02:45:52 +02:00
|
|
|
$this->add_app('phpgwapi');
|
|
|
|
$this->add_app($this->currentapp);
|
2001-06-15 23:23:46 +02:00
|
|
|
}
|
|
|
|
|
2002-05-20 02:45:52 +02:00
|
|
|
$this->loaded = True;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@function add_app
|
|
|
|
@abstract loads all app phrases into lang
|
|
|
|
@param $lang user lang variable (defaults to en)
|
|
|
|
*/
|
|
|
|
function add_app($app)
|
|
|
|
{
|
|
|
|
//echo '<br>add_app(): adding phrases from: ' . $app;
|
|
|
|
define('SEP',filesystem_separator());
|
|
|
|
|
|
|
|
$userlang = $this->userlang ? $this->userlang : 'en';
|
2002-05-20 03:11:27 +02:00
|
|
|
//echo '<br>add_app(): userlang is: ' . $userlang;
|
2002-05-20 02:45:52 +02:00
|
|
|
|
2001-06-15 23:23:46 +02:00
|
|
|
$fn = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup' . SEP . 'phpgw_' . $userlang . '.lang';
|
2002-05-21 05:03:22 +02:00
|
|
|
if(!@file_exists($fn))
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
|
|
|
$fn = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup' . SEP . 'phpgw_en.lang';
|
|
|
|
}
|
|
|
|
|
2002-05-21 05:03:22 +02:00
|
|
|
if(@file_exists($fn))
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
2002-05-20 03:11:27 +02:00
|
|
|
$fp = fopen($fn,'r');
|
2002-05-20 02:45:52 +02:00
|
|
|
while($data = fgets($fp,8000))
|
2001-06-15 23:23:46 +02:00
|
|
|
{
|
|
|
|
list($message_id,$app_name,$null,$content) = explode("\t",$data);
|
2002-05-20 02:45:52 +02:00
|
|
|
//echo '<br>add_app(): adding phrase: $this->lang["'.$message_id.'"]=' . trim($content);
|
|
|
|
$this->lang[$message_id] = trim($content);
|
2001-06-15 23:23:46 +02:00
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|