egroupware_official/phpgwapi/inc/class.translation_sql.inc.php

123 lines
4.4 KiB
PHP
Raw Normal View History

<?php
/**************************************************************************\
2001-01-13 11:18:50 +01:00
* phpGroupWare API - Translation class for SQL *
* This file written by Joseph Engo <jengo@phpgroupware.org> *
* and Dan Kuykendall <seek3r@phpgroupware.org> *
* Handles multi-language support use SQL tables *
* Copyright (C) 2000, 2001 Joseph Engo *
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
2001-01-13 11:18:50 +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$ */
2001-06-15 23:29:33 +02:00
class translation
{
2002-02-17 19:43:31 +01:00
function translate($key, $vars=False)
2001-06-15 23:29:33 +02:00
{
2002-02-17 19:43:31 +01:00
if(!$vars)
2001-11-23 20:35:45 +01:00
{
$vars = array();
}
2001-06-15 23:29:33 +02:00
$ret = $key;
2002-02-17 19:43:31 +01:00
/*
Check also if $GLOBALS['lang'] is a array.
php-nuke and postnuke are using $GLOBALS['lang'], too,
as string.
This makes many problems.
*/
if(isset($GLOBALS['lang'][strtolower($key)]) && $GLOBALS['lang'][strtolower($key)])
{
$ret = $GLOBALS['lang'][strtolower($key)];
}
elseif(!isset($GLOBALS['lang']) || !$GLOBALS['lang'] || !is_array($GLOBALS['lang']))
2001-06-15 23:29:33 +02:00
{
$GLOBALS['lang'] = array();
2002-02-17 19:43:31 +01:00
if(isset($GLOBALS['phpgw_info']['user']['preferences']['common']['lang']) &&
2001-08-31 10:45:44 +02:00
$GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
2001-06-15 23:29:33 +02:00
{
2001-08-31 10:45:44 +02:00
$userlang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
2001-06-15 23:29:33 +02:00
}
else
{
$userlang = 'en';
}
2002-02-17 19:43:31 +01:00
$sql = "SELECT message_id,content FROM lang WHERE lang LIKE '" . $userlang
. "' AND (app_name LIKE '" . $GLOBALS['phpgw_info']['flags']['currentapp']
. "' OR app_name LIKE 'common' OR app_name LIKE 'all')";
2001-08-31 10:45:44 +02:00
if (strcasecmp ($GLOBALS['phpgw_info']['flags']['currentapp'], 'common')>0)
2001-06-15 23:29:33 +02:00
{
2002-02-17 19:43:31 +01:00
$sql .= ' ORDER BY app_name ASC';
2001-06-15 23:29:33 +02:00
}
else
{
2002-02-17 19:43:31 +01:00
$sql .= ' ORDER BY app_name DESC';
2001-06-15 23:29:33 +02:00
}
2001-08-31 10:45:44 +02:00
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
$GLOBALS['phpgw']->db->next_record();
$count = $GLOBALS['phpgw']->db->num_rows();
2002-02-17 19:43:31 +01:00
for($idx = 0; $idx < $count; ++$idx)
2001-06-15 23:29:33 +02:00
{
2002-02-17 19:43:31 +01:00
$GLOBALS['lang'][strtolower($GLOBALS['phpgw']->db->f('message_id'))] = $GLOBALS['phpgw']->db->f('content');
2001-08-31 10:45:44 +02:00
$GLOBALS['phpgw']->db->next_record();
2001-06-15 23:29:33 +02:00
}
2002-02-17 19:43:31 +01:00
$ret = $GLOBALS['lang'][strtolower($key)] ? $GLOBALS['lang'][strtolower($key)] : $key . '*';
2001-06-15 23:29:33 +02:00
}
2002-02-17 19:43:31 +01:00
2001-06-15 23:29:33 +02:00
$ndx = 1;
2002-02-17 19:43:31 +01:00
while(list($key,$val) = each($vars))
2001-06-15 23:29:33 +02:00
{
$ret = preg_replace( "/%$ndx/", $val, $ret );
++$ndx;
}
return $ret;
}
function add_app($app)
{
2002-02-17 19:43:31 +01:00
/*
post-nuke and php-nuke are using $GLOBALS['lang'], too.
But not as array!
This produces very strange results.
*/
if(!is_array($GLOBALS['lang']))
{
$GLOBALS['lang'] = array();
}
2002-02-17 19:43:31 +01:00
if($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
2001-06-15 23:29:33 +02:00
{
2001-08-31 10:45:44 +02:00
$userlang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
2001-06-15 23:29:33 +02:00
}
else
{
$userlang = 'en';
}
2002-02-17 19:43:31 +01:00
$sql = "SELECT message_id,content FROM lang WHERE lang LIKE '".$userlang."' AND app_name LIKE '".$app."'";
2001-08-31 10:45:44 +02:00
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
$GLOBALS['phpgw']->db->next_record();
$count = $GLOBALS['phpgw']->db->num_rows();
2002-02-17 19:43:31 +01:00
for($idx = 0; $idx < $count; ++$idx)
2001-06-15 23:29:33 +02:00
{
2001-08-31 10:45:44 +02:00
$GLOBALS['lang'][strtolower ($GLOBALS['phpgw']->db->f('message_id'))] = $GLOBALS['phpgw']->db->f('content');
$GLOBALS['phpgw']->db->next_record();
2001-06-15 23:29:33 +02:00
}
}
}