From 297447b42198b518d8108fc7d4794da489cf9608 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 16 Oct 2003 19:51:56 +0000 Subject: [PATCH] synchroniced it with the developer_tools::class.solangfile.inc.php 1.19 --- etemplate/inc/class.solangfile.inc.php | 326 ++++++++++++++----------- 1 file changed, 184 insertions(+), 142 deletions(-) diff --git a/etemplate/inc/class.solangfile.inc.php b/etemplate/inc/class.solangfile.inc.php index 063696339c..7fd91425eb 100644 --- a/etemplate/inc/class.solangfile.inc.php +++ b/etemplate/inc/class.solangfile.inc.php @@ -24,13 +24,21 @@ var $loaded_apps = array(); // Loaded app langs var $functions = array( // functions containing phrases to translate and param# - 'lang' => array(1), - 'create_input_box' => array(1,3), - 'create_check_box' => array(1,3), - 'create_select_box' => array(1,4), - 'create_text_area' => array(1,5), + 'lang' => array(1), + 'create_input_box' => array(1,3), + 'create_check_box' => array(1,3), + 'create_select_box' => array(1,4), + 'create_text_area' => array(1,5), + 'create_notify' => array(1,5), 'create_password_box' => array(1,3) ); + var $files = array( + 'config.tpl' => 'config', + 'hook_admin.inc.php' => 'file_admin', + 'hook_preferences.inc.php' => 'file_preferences', + 'hook_sidebox_menu.inc.php' => 'file', + 'hook_acl_manager.inc.php' => 'acl_manager' + ); var $public_functions = array( 'index' => True @@ -41,11 +49,112 @@ $this->db = $GLOBALS['phpgw']->db; } - function parse_php_app($fd,$plist) + function fetch_keys($app,$arr) + { + if (!is_array($arr)) + { + return; + } + foreach($arr as $key => $val) + { + $this->plist[$key] = $app; + } + } + + function config_file($app,$fname) + { + //echo "

solangfile::config_file(app='$app',fname='$fname')

\n"; + $lines = file($fname); + + if ($app != 'setup') + { + $app = 'admin'; + } + foreach($lines as $n => $line) + { + while (ereg('\{lang_([^}]+)\}(.*)',$line,$found)) + { + $lang = str_replace('_',' ',$found[1]); + $this->plist[$lang] = $app; + + $line = $found[2]; + } + } + } + + function special_file($app,$fname,$langs_in) + { + //echo "

solangfile::special_file(app='$app',fname='$fname',langs_in='$langs_in')

\n"; + switch ($langs_in) + { + case 'config': + $this->config_file($app,$fname); + return; + case 'file_admin': + case 'file_preferences': + $app = substr($langs_in,5); + break; + case 'phpgwapi': + $app = 'common'; + break; + } + if (!function_exists('display_sidebox')) + { + function display_sidebox($appname,$menu_title,$file) // hook_sidebox_menu + { + unset($file['_NewLine_']); + $GLOBALS['file'] += $file; + } + function display_section($appname,$file,$file2='') // hook_preferences, hook_admin + { + if (is_array($file2)) + { + $file = $file2; + } + $GLOBALS['file'] += $file; + } + } + $GLOBALS['file'] = array(); + unset($GLOBALS['acl_manager']); + include($fname); + + if (isset($GLOBALS['acl_manager'])) // hook_acl_manager + { + foreach($GLOBALS['acl_manager'] as $app => $data) + { + foreach ($data as $item => $arr) + { + foreach ($arr as $key => $val) + { + switch ($key) + { + case 'name': + $this->plist[$val] = $app; + break; + case 'rights': + foreach($val as $lang => $right) + { + $this->plist[$lang] = $app; + } + break; + } + } + } + } + } + if (count($GLOBALS['file'])) // hook_{admin|preferences|sidebox_menu} + { + foreach ($GLOBALS['file'] as $lang => $link) + { + $this->plist[$lang] = $app; + } + } + } + + function parse_php_app($app,$fd) { $reg_expr = '('.implode('|',array_keys($this->functions)).")[ \t]*\([ \t]*(.*)$"; define('SEP',filesystem_separator()); - list($app) = explode(SEP,$fd); $d=dir($fd); while ($fn=$d->read()) { @@ -53,12 +162,20 @@ { if (($fn!='.')&&($fn!='..')&&($fn!='CVS')) { - $plist=$this->parse_php_app($fd.$fn.SEP,$plist); + $this->parse_php_app($app,$fd.$fn.SEP); } } - elseif ((strpos($fn,'.php')>1) && (is_readable($fd.$fn))) + elseif (is_readable($fd.$fn)) { - $lines = file($fd.SEP.$fn); + if (isset($this->files[$fn])) + { + $this->special_file($app,$fd.$fn,$this->files[$fn]); + } + if (strpos($fn,'.php') === False) + { + continue; + } + $lines = file($fd.$fn); foreach($lines as $n => $line) { @@ -91,8 +208,8 @@ //echo "next2=$next, phrase='$phrase'
\n"; if ($args[0] == $i) { - //if (!isset($plist[$phrase])) echo ">>>$phrase<<<
\n"; - $plist[$phrase] = $app; + //if (!isset($this->plist[$phrase])) echo ">>>$phrase<<<
\n"; + $this->plist[$phrase] = $app; array_shift($args); if (!count($args)) { @@ -101,7 +218,7 @@ } $rest = substr($rest,$next+1); } - if(!ereg("[ \t\n]*,[ \t\n]*(.*)$",$rest,$parts)) + if(!ereg("[ \t\n]*,[ \t\n]*(.*)$",$rest,$parts)) { break; // nothing found } @@ -113,7 +230,6 @@ } } $d->close(); - return ($plist); } function missing_app($app,$userlang=en) @@ -121,61 +237,11 @@ $cur_lang=$this->load_app($app,$userlang); define('SEP',filesystem_separator()); $fd = PHPGW_SERVER_ROOT . SEP . $app . SEP; - $plist=array(); - $plist = $this->parse_php_app($fd,$plist); - reset($plist); - return($plist); - } + $this->plist = array(); + $this->parse_php_app($app == 'phpgwapi' ? 'common' : $app,$fd); - /*! - @function add_app - @abstract loads all app phrases into langarray - @param $lang user lang variable (defaults to en) - */ - function add_app($app,$userlang='en') - { - define('SEP',filesystem_separator()); - - $fd = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup'; - $fn = $fd . SEP . 'phpgw_' . $userlang . '.lang'; - if (@is_writeable($fn) || is_writeable($fd)) - { - $wr = True; - } - $this->src_apps = array($app => $app); - - if (file_exists($fn)) - { - $this->src_file = $fn; - $fp = fopen($fn,'rb'); - while ($data = fgets($fp,8000)) - { - list($message_id,$app_name,$null,$content) = explode("\t",$data); - if(!$message_id) - { - continue; - } - //echo '
add_app(): adding phrase: $this->langarray["'.$message_id.'"]=' . trim($content); - $_mess_id = strtolower(trim($message_id)); - $app_name = trim($app_name); - $this->langarray[$_mess_id]['message_id'] = $_mess_id; - $this->langarray[$_mess_id]['app_name'] = $app_name; - $this->langarray[$_mess_id]['content'] = trim($content); - $this->src_apps[$app_name] = $app_name; - } - fclose($fp); - } - else - { - $this->src_file = lang('no file'); - } - // stuff class array listing apps that are included already - $this->loaded_apps[$userlang]['filename'] = $fn; - $this->loaded_apps[$userlang]['writeable'] = $wr; - - if($this->debug) { _debug_array($this->langarray); } - @ksort($this->langarray); - return $this->langarray; + reset($this->plist); + return($this->plist); } /*! @@ -183,41 +249,54 @@ @abstract loads all app phrases into langarray @param $lang user lang variable (defaults to en) */ - function load_app($app,$userlang='en') + function load_app($app,$userlang='en',$target=True) { define('SEP',filesystem_separator()); - $fd = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup'; + $langarray = array(); + $fd = PHPGW_SERVER_ROOT . SEP . $app . SEP . ($app == 'setup' ? 'lang' : 'setup'); $fn = $fd . SEP . 'phpgw_' . $userlang . '.lang'; if (@is_writeable($fn) || is_writeable($fd)) { $wr = True; } + $from = $GLOBALS['phpgw']->translation->charset($userlang); + $to = $GLOBALS['phpgw']->translation->system_charset; + //echo "

solangfile::load_app('$app','$userlang') converting from charset('$userlang')='$from' to '$to'

\n"; + if (file_exists($fn)) { - $this->tgt_file = $fn; if ($fp = @fopen($fn,'rb')) { while ($data = fgets($fp,8000)) { - list($message_id,$app_name,$null,$content) = explode("\t",$data); - if(!$message_id) - { - continue; - } - //echo '
add_app(): adding phrase: $this->langarray["'.$message_id.'"]=' . trim($content); - $_mess_id = strtolower(trim($message_id)); - $langarray[$_mess_id]['message_id'] = $_mess_id; - $langarray[$_mess_id]['app_name'] = trim($app_name); - $langarray[$_mess_id]['content'] = trim($content); + list($message_id,$app_name,$null,$content) = explode("\t",$data); + if(!$message_id) + { + continue; + } + //echo '
load_app(): adding phrase: $this->langarray["'.$message_id.'"]=' . trim($content); + $_mess_id = strtolower(trim($message_id)); + $langarray[$_mess_id]['message_id'] = $_mess_id; + $langarray[$_mess_id]['app_name'] = trim($app_name); + $langarray[$_mess_id]['content'] = + $GLOBALS['phpgw']->translation->convert(trim($content),$from,$to); } fclose($fp); } } else { - $this->tgt_file = lang('no file'); + $fn = lang('no file'); + } + if ($target) + { + $this->tgt_file = $fn; + } + else + { + $this->src_file = $fn; } // stuff class array listing apps that are included already $this->loaded_apps[$userlang]['filename'] = $fn; @@ -251,9 +330,13 @@ return $languages; } - function write_file($app_name,$langarray,$userlang) + function write_file($app_name,$langarray,$userlang,$which='target') { - $fn = PHPGW_SERVER_ROOT . SEP . $app_name . SEP . 'setup' . SEP . 'phpgw_' . $userlang . '.lang'; + $to = $GLOBALS['phpgw']->translation->charset($userlang); + $from = $GLOBALS['phpgw']->translation->system_charset; + //echo "

solangfile::write_file('$app_name',,'$userlang') converting from '$from' to charset('$userlang')='$to'

\n"; + + $fn = PHPGW_SERVER_ROOT . SEP . $app_name . SEP . ($app_name == 'setup' ? 'lang' : 'setup') . SEP . 'phpgw_' . $userlang . '.lang'; if (file_exists($fn)) { $backup = $fn . '.old'; @@ -263,72 +346,31 @@ $fp = fopen($fn,'wb'); while(list($mess_id,$data) = @each($langarray)) { + $data['content'] = $GLOBALS['phpgw']->translation->convert(trim($data['content']),$from,$to); + fwrite($fp,$mess_id . "\t" . $data['app_name'] . "\t" . $userlang . "\t" . $data['content'] . "\n"); } fclose($fp); - return; + + if ($which == 'source') + { + $this->src_file = $fn; + } + else + { + $this->tgt_file = $fn; + } + return $fn; } - function loaddb($app_name,$userlang) + function loaddb($app_name,$userlangs) { - $this->db->transaction_begin(); - - $langarray = $this->load_app($app_name,$userlang); - - @reset($langarray); - while (list($x,$data) = @each($langarray)) + if (!is_array($userlangs)) { - if (strlen($data['message_id']) > MAX_MESSAGE_ID_LENGTH) - { - $data['message_id'] = substr($data['message_id'],0,MAX_MESSAGE_ID_LENGTH); - } - - $message_id = $this->db->db_addslashes(substr($data['message_id'],0,MAX_MESSAGE_ID_LENGTH)); - - $addit = False; - /*echo '

 checking ' . $data['message_id'] . "\t" . $data['app_name'] . "\t" . $userlang . "\t" . $data['content'];*/
-				$this->db->query("SELECT COUNT(*) FROM phpgw_lang"
-					."  WHERE message_id='$message_id' AND lang='$userlang' AND app_name='$app_name'",__LINE__,__FILE__);
-				$this->db->next_record();
-
-				if ($this->db->f(0) == 0)
-				{
-					$addit = True;
-					/* echo '... no
'; */ - } - else - { - /* echo '... yes'; */ - } - - if ($addit) - { - if($data['message_id'] && $data['content']) - { - /* echo "
adding - insert into lang values ('" . $data['message_id'] . "','$app_name','$userlang','" . $data['content'] . "')"; */ - $this->db->query("INSERT into phpgw_lang VALUES ('$message_id','$app_name','$userlang','" - . $this->db->db_addslashes($data['content']) . "')",__LINE__,__FILE__); - } - } - else - { - if($data['message_id'] && $data['content']) - { - $this->db->query("UPDATE phpgw_lang SET content='". $this->db->db_addslashes($data['content']) . "'" - . " WHERE message_id='message_id'" - . " AND app_name='$app_name' AND lang='$userlang'",__LINE__,__FILE__); - if ($this->db->affected_rows() > 0) - { -/* - echo "
changing - update lang set content='". $data['content'] . "'" - . " where message_id='" . $data['message_id'] ."'" - . " and app_name='$app_name' and lang='$userlang'"; -*/ - } - } - } + $userlangs = array($userslangs => $userlangs); } - $this->db->transaction_commit(); + $GLOBALS['phpgw']->translation->install_langs($userlangs,'addmissing',$app_name); + return lang('done'); } }