| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Translation Editor * 4 * http://www.egroupware.org * 5 * -------------------------------------------- * 6 * This program is free software; you can redistribute it and/or modify it * 7 * under the terms of the GNU General Public License as published by the * 8 * Free Software Foundation; either version 2 of the License, or (at your * 9 * option) any later version. * 10 \**************************************************************************/ 11 12 /* $Id: class.bolangfile.inc.php 19608 2005-11-05 08:51:35Z ralfbecker $ */ 13 14 class bolangfile 15 { 16 var $total; 17 var $debug = False; 18 var $so; 19 var $loaded_apps = array(); 20 var $source_langarray = ''; 21 var $missing_langarray = ''; 22 var $target_langarray = ''; 23 var $extra_langarray = array(); 24 var $src_file; 25 var $src_apps = array(); 26 var $tgt_file; 27 var $tgt_lang; 28 29 function bolangfile() 30 { 31 $this->so =& CreateObject('developer_tools.solangfile'); 32 settype($this->source_langarray,'string'); 33 settype($this->target_langarray,'string'); 34 settype($this->missing_langarray,'string'); 35 } 36 37 /* Sessions used to save state and not reread the langfile between adding/deleting phrases */ 38 function save_sessiondata($source='##unset##',$target='##unset##') 39 { 40 if ($source == '##unset##') 41 { 42 $source = &$this->source_langarray; 43 } 44 if ($target == '##unset##') 45 { 46 $target = &$this->target_langarray; 47 } 48 if($this->debug) { echo '<br>Save:'; _debug_array($source); } 49 $GLOBALS['egw']->session->appsession('developer_source_lang','developer_tools',$source); 50 if($this->debug) { echo '<br>Save:'; _debug_array($target); } 51 $GLOBALS['egw']->session->appsession('developer_target_lang','developer_tools',$target); 52 $GLOBALS['egw']->session->appsession('developer_source_file','developer_tools',$this->src_file); 53 $GLOBALS['egw']->session->appsession('developer_target_file','developer_tools',$this->tgt_file); 54 $GLOBALS['egw']->session->appsession('developer_t_lang','developer_tools',$this->tgt_lang); 55 $GLOBALS['egw']->session->appsession('developer_loaded_apps','developer_tools',$this->loaded_apps); 56 $GLOBALS['egw']->session->appsession('developer_src_apps','developer_tools',$this->src_apps); 57 $GLOBALS['egw']->session->appsession('developer_missing_lang','developer_tools',$this->missing_langarray); 58 } 59 60 function read_sessiondata() 61 { 62 $source = $GLOBALS['egw']->session->appsession('developer_source_lang','developer_tools'); 63 if($this->debug) { echo '<br>Read:'; _debug_array($source); } 64 65 $target = $GLOBALS['egw']->session->appsession('developer_target_lang','developer_tools'); 66 if($this->debug) { echo '<br>Read:'; _debug_array($target); } 67 68 $src_file = $GLOBALS['egw']->session->appsession('developer_source_file','developer_tools'); 69 $tgt_file = $GLOBALS['egw']->session->appsession('developer_target_file','developer_tools'); 70 $tgt_lang = $GLOBALS['egw']->session->appsession('developer_t_lang','developer_tools'); 71 $loaded_apps = $GLOBALS['egw']->session->appsession('developer_loaded_apps','developer_tools'); 72 $src_apps = $GLOBALS['egw']->session->appsession('developer_src_apps','developer_tools'); 73 $missing = $GLOBALS['egw']->session->appsession('developer_missing_lang','developer_tools'); 74 75 $this->set_sessiondata($source,$target,$src_file,$tgt_file,$tgt_lang,$loaded_apps,$src_apps,$missing); 76 } 77 78 function set_sessiondata($source,$target,$src_file,$tgt_file,$tgt_lang,$loaded_apps,$src_apps,$missing) 79 { 80 $this->source_langarray = $source; 81 $this->target_langarray = $target; 82 $this->src_file = $src_file; 83 $this->tgt_file = $tgt_file; 84 $this->tgt_lang = $tgt_lang; 85 $this->loaded_apps = $loaded_apps; 86 $this->src_apps = $src_apps; 87 $this->missing_langarray = $missing; 88 } 89 90 function clear_sessiondata() 91 { 92 $GLOBALS['egw']->session->appsession('developer_source_lang','developer_tools',''); 93 $GLOBALS['egw']->session->appsession('developer_target_lang','developer_tools',''); 94 $GLOBALS['egw']->session->appsession('developer_source_file','developer_tools',''); 95 $GLOBALS['egw']->session->appsession('developer_target_file','developer_tools',''); 96 $GLOBALS['egw']->session->appsession('developer_t_lang','developer_tools',''); 97 $GLOBALS['egw']->session->appsession('developer_loaded_apps','developer_tools',''); 98 } 99 100 function addphrase($entry) 101 { 102 /* _debug_array($this->source_langarray);exit; */ 103 if (empty($entry['content'])) $entry['content'] = $entry['message_id']; 104 105 $mess_id = strtolower(trim($entry['message_id'])); 106 $this->source_langarray[$mess_id] = array( 107 'message_id' => $mess_id, 108 'content' => $entry['content'], 109 'app_name' => $entry['app_name'] == 'phpgwapi' ? 'common' : $entry['app_name'], 110 'lang' => 'en' 111 ); 112 @ksort($this->source_langarray); 113 114 if (!empty($entry['target'])) 115 { 116 $this->target_langarray[$mess_id] = array( 117 'message_id' => $mess_id, 118 'content' => $entry['target'], 119 'app_name' => $entry['app_name'] == 'phpgwapi' ? 'common' : $entry['app_name'], 120 'lang' => $this->tgt_lang 121 ); 122 } 123 } 124 125 function movephrase($mess='') 126 { 127 if ($mess !='' && ($this->missing_langarray[$mess]['message_id'])) 128 { 129 $this->source_langarray[$mess] = $m = array( 130 'message_id' => $this->missing_langarray[$mess]['message_id'], 131 'content' => $this->missing_langarray[$mess]['content'], 132 'app_name' => $this->missing_langarray[$mess]['app_name'], 133 'lang' => 'en' 134 ); 135 @ksort($this->source_langarray); 136 reset($this->source_langarray); 137 138 if ($this->tgt_lang == 'en') 139 { 140 $this->target_langarray[$mess] = $m; 141 142 @ksort($this->target_langarray); 143 reset($this->target_langarray); 144 } 145 } 146 //else echo "'$mess' not found in missing_langarray !!!<br>\n"; 147 } 148 149 function missing_app($app,$userlang='en') 150 { 151 $this->missing_langarray = array(); 152 153 if (!is_array($this->extra_langarray['common'])) 154 { 155 $this->extra_langarray['common'] = $this->so->load_app('phpgwapi',$userlang); 156 } 157 $plist = $this->so->missing_app($app = trim($app),$userlang); 158 159 foreach($plist as $p => $loc) 160 { 161 $_mess_id = strtolower(trim($p)); 162 if ($loc != $app) 163 { 164 if (!is_array($this->extra_langarray[$loc])) 165 { 166 $this->extra_langarray[$loc] = $this->so->load_app($loc,$userlang); 167 //echo "<p>loading translations for '$loc'</p>\n"; 168 } 169 } 170 if (!empty($_mess_id) && !$this->source_langarray[$_mess_id] && 171 !$this->extra_langarray['common'][$_mess_id] && 172 ($app == $loc || !$this->extra_langarray[$loc][$_mess_id])) 173 { 174 //echo "Havn't found '$_mess_id'/$loc !!!<br>\n"; 175 $this->missing_langarray[$_mess_id] = array( 176 'message_id' => $_mess_id, 177 'app_name' => $loc, 178 'content' => $p 179 ); 180 } 181 } 182 if (is_array($this->missing_langarray)) 183 { 184 reset ($this->missing_langarray); 185 @ksort($this->missing_langarray); 186 } 187 return $this->missing_langarray; 188 } 189 190 function add_app($app,$userlang='en') 191 { 192 if(gettype($this->source_langarray) == 'array') 193 { 194 return $this->source_langarray; 195 } 196 $this->source_langarray = $this->so->load_app($app,$userlang,False); 197 $this->src_file = $this->so->src_file; 198 $this->loaded_apps = $this->so->loaded_apps; 199 $this->src_apps = $this->so->src_apps; 200 return $this->source_langarray; 201 } 202 203 function load_app($app,$userlang='en') 204 { 205 if(gettype($this->target_langarray) == 'array') 206 { 207 if ($this->tgt_lang == $userlang) 208 { 209 return $this->target_langarray; 210 } 211 } 212 $this->target_langarray = $this->so->load_app($app,$userlang); 213 $this->tgt_file = $this->so->tgt_file; 214 $this->tgt_lang = $userlang; 215 $this->loaded_apps = $this->so->loaded_apps; 216 return $this->target_langarray; 217 } 218 219 function write_file($which,$app_name,$userlang) 220 { 221 switch ($which) 222 { 223 case 'source': 224 $this->src_file = $this->so->write_file($app_name,$this->source_langarray,$userlang,$which); 225 break; 226 case 'target': 227 // removing phrases not in the source language 228 $before = count($this->target_langarray); 229 $this->target_langarray = array_intersect_assoc($this->target_langarray,$this->source_langarray); 230 if ($before > ($after = count($this->target_langarray))) 231 { 232 echo '<br />'. lang('Removed %1 phrases from the target language, as they are not present in the source language!',$before-$after)."\n"; 233 } 234 $this->tgt_file = $this->so->write_file($app_name,$this->target_langarray,$userlang,$which); 235 break; 236 default: 237 break; 238 } 239 $this->save_sessiondata(); 240 } 241 242 function loaddb($app_name,$userlangs) 243 { 244 $GLOBALS['egw']->invalidate_session_cache(); // otherwise you habe to logout to see the changes, if the session-cache is enabled 245 246 return $this->so->loaddb($app_name,$userlangs); 247 } 248 } 249 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |