[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] api class.lang.php, NONE, 1.1.2.1 class.apps.php, 1.
From: |
Dan Kuykendall <address@hidden> |
Subject: |
[Phpgroupware-cvs] api class.lang.php, NONE, 1.1.2.1 class.apps.php, 1.1.1.1, 1.1.1.1.2.1 class.phpgw.php, 1.1.1.1.2.2, 1.1.1.1.2.3 class.prefs.php, 1.1.1.1, 1.1.1.1.2.1 class.xmltool.php, 1.1.1.1, 1.1.1.1.2.1 starter.inc.php, 1.1.1.1.2.1, 1.1.1.1.2.2 |
Date: |
Fri, 24 Oct 2003 22:09:46 +0000 |
Update of /cvsroot/phpgroupware/api
In directory subversions:/tmp/cvs-serv22601/api
Modified Files:
Tag: proposal-branch
class.apps.php class.phpgw.php class.prefs.php
class.xmltool.php starter.inc.php
Added Files:
Tag: proposal-branch
class.lang.php
Log Message:
added translation support
Index: starter.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/starter.inc.php,v
retrieving revision 1.1.1.1.2.1
retrieving revision 1.1.1.1.2.2
diff -C2 -d -r1.1.1.1.2.1 -r1.1.1.1.2.2
*** starter.inc.php 23 Oct 2003 20:38:24 -0000 1.1.1.1.2.1
--- starter.inc.php 24 Oct 2003 22:09:44 -0000 1.1.1.1.2.2
***************
*** 105,108 ****
--- 105,109 ----
$GLOBALS['phpgw'] = createobject('api_phpgw');
$GLOBALS['msgbox'] = createobject('api_msgbox');
+ $GLOBALS['lang'] = createobject('api_lang');
$GLOBALS['phpgw']->db = createobject('api_db');
$GLOBALS['phpgw']->db->Host =
$GLOBALS['phpgw_data']['server']['db_host'];
Index: class.apps.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/class.apps.php,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.1
diff -C2 -d -r1.1.1.1 -r1.1.1.1.2.1
*** class.apps.php 23 Oct 2003 07:25:01 -0000 1.1.1.1
--- class.apps.php 24 Oct 2003 22:09:44 -0000 1.1.1.1.2.1
***************
*** 40,44 ****
while ($this->db->next_record())
{
!
$this->allapps[$this->db->f('app_name')] =
array('name'=>$this->db->f('app_name'), 'title'=>$this->db->f('app_title'));
}
}
--- 40,45 ----
while ($this->db->next_record())
{
! $title =
$GLOBALS['lang']->trans($this->db->f('app_title'), $this->db->f('app_name'));
!
$this->allapps[$this->db->f('app_name')] =
array('name'=>$this->db->f('app_name'), 'title'=>$title);
}
}
--- NEW FILE: class.lang.php ---
<?php
/**************************************************************************\
* phpGroupWare
*
* http://www.phpgroupware.org
*
* This file written by Dan Kuykendall <address@hidden> *
* Copyright (C) 2003 Dan Kuykendall
*
*
-------------------------------------------------------------------------*
* 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.lang.php,v 1.1.2.1 2003/10/24 22:09:44 seek3r Exp $ */
class api_lang
{
var $messages = array();
var $domain = 'messages';
var $language = 'en';
var $registered_app = 'api';
var $envset = False;
function api_lang()
{
$this->switchlang();
}
function add($strings, $app = 'api')
{
$this->messages[$app][$strings] = True;
}
function get()
{
$args = new safe_args();
$args->set('msg', '##REQUIRED##', 'any');
$args->set('app', '##NOTSET##', 'string');
$args = $args->get(func_get_args(),__LINE__,__FILE__);
if(!isset($args['app']))
{
if(isset($GLOBALS['phpgw_data']['api']['op']))
{
list($args['app']) =
explode('.',$GLOBALS['phpgw_data']['api']['op']);
}
else
{
$args['app'] = 'api';
}
}
$this->switchlang();
$this->switchapp($args['app']);
$result = gettext($args['msg']);
if($result == $args['msg'] && $this->registered_app !=
'api')
{
$this->switchapp('api');
$result = gettext($args['msg']);
}
return $result;
}
function trans()
{
return $this->get(func_get_args());
}
function switchapp($app = 'api')
{
if($app != $this->registered_app &&
is_dir(PHPGW_ROOT.'/'.$app.'/locale'))
{
bindtextdomain($this->domain,
PHPGW_ROOT.'/'.$app.'/locale');
$this->registered_app = $app;
}
}
function switchlang()
{
if(isset($GLOBALS['phpgw_data']['prefs']['api.lang'])
&& $this->language != $GLOBALS['phpgw_data']['prefs']['api.lang'])
{
$this->language =
$GLOBALS['phpgw_data']['prefs']['api.lang'];
$this->envset = False;
}
$this->language = 'es';
if(!$this->envset)
{
putenv('LANG='.$this->language);
setlocale(LC_ALL, $this->language);
$this->envset = True;
}
}
function addtoxml()
{
$this->switchlang();
if(count($this->messages) > 0)
{
foreach($this->messages as $app=>$strings)
{
$this->switchapp($app);
foreach($strings as $msg=>$val)
{
$translated = gettext($msg);
if($translated == $msg && $app
!= 'api')
{
$this->switchapp('api');
$translated =
gettext($msg);
$this->switchapp($app);
}
$lang_node =
createobject('api_xmltool',array('node_type'=>'node','name'=>'LANG'));
$lang_node->set_attribute('name', $msg);
$lang_node->set_value($translated);
$GLOBALS['phpgw_xmldoc']->add_node($lang_node);
}
}
}
}
function addfromskin($xsl_files)
{
foreach($xsl_files as $key=>$val)
{
$valid_file = False;
list($app,$file) = explode('.',$val);
$skindir =
PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.$GLOBALS['phpgw_data']['prefs']['api.skin'];
$filename = $skindir.SEP.$file.'_lang.xml';
if(file_exists($filename))
{
$valid_file = True;
}
elseif($GLOBALS['phpgw_data']['prefs']['api.skin'] != 'default')
{
$def_skindir =
PHPGW_ROOT.SEP.$app.SEP.'skins'.SEP.'default';
$def_filename =
$def_skindir.SEP.$file.'_lang.xml';
if(file_exists($def_filename))
{
$skindir = $def_skindir;
$filename = $def_filename;
$valid_file = True;
}
}
if($valid_file)
{
$f = fopen ($filename, 'r');
$xmlstring = fread ($f,
filesize($filename));
fclose ($f);
$messages = xml2var($xmlstring);
unset($xmlstring);
$this->switchapp($app);
foreach ($messages['message'] as $val)
{
$translated = gettext($val);
if($translated == $val && $app
!= 'api')
{
$this->switchapp('api');
$translated =
gettext($val);
$this->switchapp($app);
}
$lang_node =
createobject('api_xmltool',array('node_type'=>'node','name'=>'LANG'));
$lang_node->set_attribute('name', $val);
$lang_node->set_value($translated);
$GLOBALS['phpgw_xmldoc']->add_node($lang_node);
}
}
}
}
}
/* cheater shortcut version */
function lang()
{
$GLOBALS['lang']->trans(func_get_args());
}
Index: class.xmltool.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/class.xmltool.php,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.1
diff -C2 -d -r1.1.1.1 -r1.1.1.1.2.1
*** class.xmltool.php 23 Oct 2003 07:25:02 -0000 1.1.1.1
--- class.xmltool.php 24 Oct 2003 22:09:44 -0000 1.1.1.1.2.1
***************
*** 515,519 ****
}
!
/*if(preg_match("(&|<)", $this->data)) // this is unnecessary with
htmlspecialchars($this->data)
{
$result .=
'<![CDATA['.$this->data.']]>';
--- 515,519 ----
}
!
/*if(preg_match("(&|<|>)", $this->data)) // this is unnecessary with
htmlspecialchars($this->data)
{
$result .=
'<![CDATA['.$this->data.']]>';
Index: class.phpgw.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/class.phpgw.php,v
retrieving revision 1.1.1.1.2.2
retrieving revision 1.1.1.1.2.3
diff -C2 -d -r1.1.1.1.2.2 -r1.1.1.1.2.3
*** class.phpgw.php 24 Oct 2003 06:22:15 -0000 1.1.1.1.2.2
--- class.phpgw.php 24 Oct 2003 22:09:44 -0000 1.1.1.1.2.3
***************
*** 34,37 ****
--- 34,38 ----
var $hooks;
var $prefs;
+ var $lang;
var $phpgw_output;
***************
*** 126,130 ****
{
$menu[] = array(
! 'title' => 'Home',
'op' => 'api.base.start',
);
--- 127,131 ----
{
$menu[] = array(
! 'title' =>
$GLOBALS['lang']->trans('Home', 'api'),
'op' => 'api.base.start',
);
***************
*** 133,137 ****
{
$menu[] = array(
! 'title' => 'Admin',
'op' => 'api.admin.start',
);
--- 134,138 ----
{
$menu[] = array(
! 'title' =>
$GLOBALS['lang']->trans('Admin', 'api'),
'op' => 'api.admin.start',
);
***************
*** 140,144 ****
{
$menu[] = array(
! 'title' => 'Preferences',
'op' => 'api.base.prefs',
);
--- 141,145 ----
{
$menu[] = array(
! 'title' =>
$GLOBALS['lang']->trans('Preferences', 'api'),
'op' => 'api.base.prefs',
);
***************
*** 147,151 ****
{
$menu[] = array(
! 'title' => 'About',
'op' => 'api.base.about',
);
--- 148,152 ----
{
$menu[] = array(
! 'title' =>
$GLOBALS['lang']->trans('About', 'api'),
'op' => 'api.base.about',
);
***************
*** 153,157 ****
}
$menu[] = array(
! 'title' => 'Logout',
'op' => 'api.base.logout',
);
--- 154,158 ----
}
$menu[] = array(
! 'title' => $GLOBALS['lang']->trans('Logout',
'api'),
'op' => 'api.base.logout',
);
***************
*** 229,232 ****
--- 230,239 ----
/* Add the API section to the XML doc */
$GLOBALS['phpgw_xmldoc']->add_node($GLOBALS['phpgw_xml_apinode']);
+
+ /* This will add the list of langs to the XML */
+ $GLOBALS['lang']->addtoxml();
+ $GLOBALS['lang']->addfromskin($this->xsl_files);
+
+ /* Add root node to the main doc object */
$this->phpgw_output->add_node($GLOBALS['phpgw_xmldoc']);
Index: class.prefs.php
===================================================================
RCS file: /cvsroot/phpgroupware/api/class.prefs.php,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.2.1
diff -C2 -d -r1.1.1.1 -r1.1.1.1.2.1
*** class.prefs.php 23 Oct 2003 07:25:01 -0000 1.1.1.1
--- class.prefs.php 24 Oct 2003 22:09:44 -0000 1.1.1.1.2.1
***************
*** 42,45 ****
--- 42,46 ----
/* all required defaults can be set here */
$this->data['phpgw_default']['api.skin'] = 'default';
+ $this->data['phpgw_default']['api.lang'] = 'en';
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] api class.lang.php, NONE, 1.1.2.1 class.apps.php, 1.1.1.1, 1.1.1.1.2.1 class.phpgw.php, 1.1.1.1.2.2, 1.1.1.1.2.3 class.prefs.php, 1.1.1.1, 1.1.1.1.2.1 class.xmltool.php, 1.1.1.1, 1.1.1.1.2.1 starter.inc.php, 1.1.1.1.2.1, 1.1.1.1.2.2,
Dan Kuykendall <address@hidden> <=