source: trunk/phpgwapi/inc/class.translation_sql.inc.php @ 199

Revision 199, 21.0 KB checked in by niltonneto, 16 years ago (diff)

Ver Ticket #149: Revisão da internacionalização

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare API - Translation class for SQL                               *
4  * This file written by Joseph Engo <jengo@phpgroupware.org>                *
5  * and Dan Kuykendall <seek3r@phpgroupware.org>                             *
6  * Handles multi-language support use SQL tables                            *
7  * Copyright (C) 2000, 2001 Joseph Engo                                     *
8  * ------------------------------------------------------------------------ *
9  * This library is part of the eGroupWare API                               *
10  * http://www.egroupware.org/api                                            *
11  * ------------------------------------------------------------------------ *
12  * This library is free software; you can redistribute it and/or modify it  *
13  * under the terms of the GNU Lesser General Public License as published by *
14  * the Free Software Foundation; either version 2.1 of the License,         *
15  * or any later version.                                                    *
16  * This library is distributed in the hope that it will be useful, but      *
17  * WITHOUT ANY WARRANTY; without even the implied warranty of               *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
19  * See the GNU Lesser General Public License for more details.              *
20  * You should have received a copy of the GNU Lesser General Public License *
21  * along with this library; if not, write to the Free Software Foundation,  *
22  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
23  \**************************************************************************/
24
25
26        // define the maximal length of a message_id, all message_ids have to be unique
27        // in this length, our column is varchar 255, but addslashes might add some length
28        if (!defined('MAX_MESSAGE_ID_LENGTH'))
29        {
30                define('MAX_MESSAGE_ID_LENGTH',230);
31        }
32        // some constanst for pre php4.3
33        if (!defined('PHP_SHLIB_SUFFIX'))
34        {
35                define('PHP_SHLIB_SUFFIX',strtoupper(substr(PHP_OS, 0,3)) == 'WIN' ? 'dll' : 'so');
36        }
37        if (!defined('PHP_SHLIB_PREFIX'))
38        {
39                define('PHP_SHLIB_PREFIX',PHP_SHLIB_SUFFIX == 'dll' ? 'php_' : '');
40        }
41
42        class translation
43        {
44                var $userlang = 'en';
45                var $loaded_apps = array();
46                var $line_rejected = array();
47
48                function translation($warnings = False)
49                {
50                        for ($i = 1; $i <= 9; $i++)
51                        {
52                                $this->placeholders[] = '%'.$i;
53                        }
54                        $this->db = is_object($GLOBALS['phpgw']->db) ? $GLOBALS['phpgw']->db : $GLOBALS['phpgw_setup']->db;
55                        if (!isset($GLOBALS['phpgw_setup']))
56                        {
57                                $this->system_charset = @$GLOBALS['phpgw_info']['server']['system_charset'];
58                        }
59                        else
60                        {
61                                $this->db->query("SELECT config_value FROM phpgw_config WHERE config_app='phpgwapi' AND config_name='system_charset'",__LINE__,__FILE__);
62                                if ($this->db->next_record())
63                                {
64                                        $this->system_charset = $this->db->f(0);
65                                }
66                        }
67                        // load multi-byte-string-extension if needed, and set its internal encodeing to your system_charset
68                        if ($this->system_charset && substr($this->system_charset,0,9) != 'iso-8859-1')
69                        {
70                                if ($this->mbstring = extension_loaded('mbstring') || @dl(PHP_SHLIB_PREFIX.'mbstring.'.PHP_SHLIB_SUFFIX))
71                                {
72                                        ini_set('mbstring.internal_encoding',$this->system_charset);
73                                        if (ini_get('mbstring.func_overload') < 7)
74                                        {
75                                                if ($warnings)
76                                                {
77                                                        echo "<p>Warning: Please set <b>mbstring.func_overload = 7</b> in your php.ini for useing <b>$this->system_charset</b> as your charset !!!</p>\n";
78                                                }
79                                        }
80                                }
81                                else
82                                {
83                                        if ($warnings)
84                                        {
85                                                echo "<p>Warning: Please get and/or enable the <b>mbstring extension</b> in your php.ini for useing <b>$this->system_charset</b> as your charset, we are defaulting to <b>iconv</b> for now !!!</p>\n";
86                                        }
87                                }
88                        }
89                }
90
91                /*
92                @function charset
93                @abstract returns the charset to use (!$lang) or the charset of the lang-files or $lang
94                */
95                function charset($lang=False)
96                {
97                        if ($lang)
98                        {
99                                if (!isset($this->charsets[$lang]))
100                                {
101                                        $this->db->query("SELECT content FROM phpgw_lang WHERE lang='$lang' AND message_id='charset' AND app_name='common'",__LINE__,__FILE__);
102                                        $this->charsets[$lang] = $this->db->next_record() ? strtolower($this->db->f(0)) : 'iso-8859-1';
103                                }
104                                return $this->charsets[$lang];
105                        }
106                        if ($this->system_charset)      // do we have a system-charset ==> return it
107                        {
108                                return $this->system_charset;
109                        }
110                        // if no translations are loaded (system-startup) use a default, else lang('charset')
111                        return !is_array(@$GLOBALS['lang']) ? 'iso-8859-1' : strtolower($this->translate('charset'));
112                }
113
114                function init()
115                {
116                        // post-nuke and php-nuke are using $GLOBALS['lang'] too
117                        // but not as array!
118                        // this produces very strange results
119                        if (!is_array(@$GLOBALS['lang']))
120                        {
121                                $GLOBALS['lang'] = array();
122                        }
123
124                        if ($GLOBALS['phpgw_info']['user']['preferences']['common']['lang'])
125                        {
126                                $this->userlang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
127                        }
128                        $this->add_app('common');
129                        if (!count($GLOBALS['lang']))
130                        {
131                                $this->userlang = 'en';
132                                $this->add_app('common');
133                        }
134                        $this->add_app($GLOBALS['phpgw_info']['flags']['currentapp']);
135                }
136
137                /*!
138                @function translate
139                @abstract translates a phrase and evtl. substitute some variables
140                @returns the translation
141                */
142                function translate($key, $vars=false, $not_found='*' )
143                {
144                        if (!is_array(@$GLOBALS['lang']) || !count($GLOBALS['lang']))
145                        {
146                                $this->init();
147                        }
148                        $ret = $key.$not_found; // save key if we dont find a translation
149
150                        if (isset($GLOBALS['lang'][$key]))
151                        {
152                                $ret = $GLOBALS['lang'][$key];
153                        }
154                        else
155                        {
156                                $new_key = strtolower(trim(substr($key,0,MAX_MESSAGE_ID_LENGTH)));
157
158                                if (isset($GLOBALS['lang'][$new_key]))
159                                {
160                                        // we save the original key for performance
161                                        $ret = $GLOBALS['lang'][$key] = $GLOBALS['lang'][$new_key];
162                                }
163                        }
164                        if (is_array($vars) && count($vars))
165                        {
166                                if (count($vars) > 1)
167                                {
168                                        $ret = str_replace($this->placeholders,$vars,$ret);
169                                }
170                                else
171                                {
172                                        $ret = str_replace('%1',$vars[0],$ret);
173                                }
174                        }
175                        return $ret;
176                }
177
178
179          function translate_async($key,$vars=false, $not_found='*' )
180          {
181            $lindex = $_SESSION['phpgw_info']['calendar']['langAlarm'];
182            if (!is_array(@$lindex) || !count($lindex))
183              {
184                $this->init();
185              }
186            $ret = $key.$not_found;     // save key if we dont find a translation
187           
188            if (isset($lindex[$key]))
189              {
190                $ret = $lindex[$key];
191              }
192            else
193              {
194                $new_key = strtolower(trim(substr($key,0,MAX_MESSAGE_ID_LENGTH)));
195               
196                if (isset($lindex[$new_key]))
197                  {
198                    // we save the original key for performance
199                    $ret = $lindex[$key] = $lindex[$new_key];
200                  }
201              }
202            if (is_array($vars) && count($vars))
203              {
204                if (count($vars) > 1)
205                  {
206                    $ret = str_replace($this->placeholders,$vars,$ret);
207                  }
208                else
209                  {
210                    $ret = str_replace('%1',$vars[0],$ret);
211                  }
212              }
213            return $ret;
214          }
215
216                /*!
217                @function add_app
218                @abstract adds translations for an application from the database to the lang-array
219                @syntax add_app($app,$lang=False)
220                @param $app name of the application to add (or 'common' for the general translations)
221                @param $lang 2-char code of the language to use or False if the users language should be used
222                */
223                function add_app($app,$lang=False)
224                {
225                        $lang = $lang ? $lang : $this->userlang;
226
227                        if (!isset($this->loaded_apps[$app]) || $this->loaded_apps[$app] != $lang)
228                        {
229                                $sql = "select message_id,content from phpgw_lang where lang='".$lang."' and app_name='".$app."'";
230                                $this->db->query($sql,__LINE__,__FILE__);
231                                while ($this->db->next_record())
232                                {
233                                        $GLOBALS['lang'][strtolower ($this->db->f('message_id'))] = $this->db->f('content');
234                                }
235                                $this->loaded_apps[$app] = $lang;
236                        }
237                }
238
239                /*!
240                @function get_installed_langs
241                @abstract returns a list of installed langs
242                @returns array with 2-character lang-code as key and descriptiv lang-name as data
243                */
244                function get_installed_langs()
245                {
246                        if (!is_array($this->langs))
247                        {
248                                $this->db->query("SELECT DISTINCT l.lang,ln.lang_name FROM phpgw_lang l,phpgw_languages ln WHERE l.lang = ln.lang_id",__LINE__,__FILE__);
249                                if (!$this->db->num_rows())
250                                {
251                                        return False;
252                                }
253                                while ($this->db->next_record())
254                                {
255                                        $this->langs[$this->db->f('lang')] = $this->db->f('lang_name');
256                                }
257                                foreach($this->langs as $lang => $name)
258                                {
259                                        $this->langs[$lang] = $this->translate($name,False,'');
260                                }
261                        }
262                        return $this->langs;
263                }
264
265                /*!
266                @function get_installed_charsets
267                @abstract returns a list of installed charsets
268                @returns array with charset as key and comma-separated list of langs useing the charset as data
269                */
270                function get_installed_charsets()
271                {
272                        if (!is_array($this->charsets))
273                        {
274                                $distinct = 'DISTINCT';
275                                switch($this->db->Type)
276                                {
277                                        case 'mssql':
278                                                $distinct = ''; // cant use distinct on text columns (l.content is text)
279                                }
280                                $this->db->query("SELECT $distinct l.lang,lx.lang_name,l.content AS charset FROM phpgw_lang l,phpgw_languages lx WHERE l.lang = lx.lang_id AND l.message_id='charset'",__LINE__,__FILE__);
281                                if (!$this->db->num_rows())
282                                {
283                                        return False;
284                                }
285                                while ($this->db->next_record())
286                                {
287                                        $data = &$this->charsets[$charset = strtolower($this->db->f('charset'))];
288                                        $lang = $this->db->f('lang_name').' ('.$this->db->f('lang').')';
289                                        if ($distinct || strstr($data,$lang) === false)
290                                        {
291                                                $data .= ($data ? ', ' : $charset.': ').$lang;
292                                        }                                               
293                                }
294                        }
295                        return $this->charsets;
296                }
297
298                /*!
299                @function convert
300                @abstract converts a string $data from charset $from to charset $to
301                @syntax convert($data,$from=False,$to=False)
302                @param $data string or array of strings to convert
303                @param $from charset $data is in or False if it should be detected
304                @param $to charset to convert to or False for the system-charset
305                @returns the converted string
306                */
307                function convert($data,$from=False,$to=False)
308                {
309                        if (is_array($data))
310                        {
311                                foreach($data as $key => $str)
312                                {
313                                        $ret[$key] = $this->convert($str,$from,$to);
314                                }
315                                return $ret;
316                        }
317
318                        if ($from)
319                        {
320                                $from = strtolower($from);
321                        }
322                        if ($to)
323                        {
324                                $to = strtolower($to);
325                        }
326
327                        if (!$from)
328                        {
329                                $from = $this->mbstring ? strtolower(mb_detect_encoding($data)) : 'iso-8859-1';
330                                if($from == 'ascii')
331                                {
332                                        $from = 'iso-8859-1';
333                                }
334                                //echo "<p>autodetected charset of '$data' = '$from'</p>\n";
335                        }
336                        /*
337                           php does not seem to support gb2312
338                           but seems to be able to decode it as EUC-CN
339                        */
340                        switch($from)
341                        {
342                                case 'gb2312':
343                                case 'gb18030':
344                                        $from = 'EUC-CN';
345                                        break;
346                                case 'us-ascii':
347                                case 'macroman':
348                                        $from = 'iso-8859-1';
349                                        break;
350                        }
351                        if (!$to)
352                        {
353                                $to = $this->charset();
354                        }
355                        if ($from == $to || !$from || !$to || !$data)
356                        {
357                                return $data;
358                        }
359                        if ($from == 'iso-8859-1' && $to == 'utf-8')
360                        {
361                                return utf8_encode($data);
362                        }
363                        if ($to == 'iso-8859-1' && $from == 'utf-8')
364                        {
365                                return utf8_decode($data);
366                        }
367                        if ($this->mbstring)
368                        {
369                                return @mb_convert_encoding($data,$to,$from);
370                        }
371                        if(function_exists('iconv'))
372                        {
373                        if($from=='EUC-CN') $from='gb18030';
374                        // the above is to workaround patch #962307
375                        // if using EUC-CN, for iconv it strickly follow GB2312 and fail
376                        // in an email on the first Traditional/Japanese/Korean character,
377                        // but in reality when people send mails in GB2312, UMA mostly use
378                        // extended GB13000/GB18030 which allow T/Jap/Korean characters.
379                                if (($data = iconv($from,$to,$data)))
380                                {
381                                        return $data;
382                                }
383                        }
384                        #die("<p>Can't convert from charset '$from' to '$to' without the <b>mbstring extension</b> !!!</p>");
385
386                        // this is not good, not convert did succed
387                        return $data;
388                }
389
390                /*!
391                @function install_langs
392                @abstract installs translations for the selected langs into the database
393                @syntax install_langs($langs,$upgrademethod='dumpold')
394                @param $langs array of langs to install (as data NOT keys (!))
395                @param $upgrademethod 'dumpold' (recommended & fastest), 'addonlynew' languages, 'addmissing' phrases
396                */
397                function install_langs($langs,$upgrademethod='dumpold',$only_app=False)
398                {
399                        @set_time_limit(0);     // we might need some time
400
401                        if (!isset($GLOBALS['phpgw_info']['server']) && $upgrademethod != 'dumpold')
402                        {
403                                $this->db->query("SELECT * FROM phpgw_config WHERE config_app='phpgwapi' AND config_name='lang_ctimes'",__LINE__,__FILE__);
404                                if ($this->db->next_record())
405                                {
406                                        $GLOBALS['phpgw_info']['server']['lang_ctimes'] = unserialize(stripslashes($this->db->f('config_value')));
407                                }
408                        }
409
410                        if (!is_array($langs) || !count($langs))
411                        {
412                                return;
413                        }
414                        $this->db->transaction_begin();
415
416                        if ($upgrademethod == 'dumpold')
417                        {
418                                // dont delete the custom main- & loginscreen messages every time
419                                $this->db->query("DELETE FROM phpgw_lang WHERE app_name != 'mainscreen' AND app_name != 'loginscreen'",__LINE__,__FILE__);
420                                //echo '<br>Test: dumpold';
421                                $GLOBALS['phpgw_info']['server']['lang_ctimes'] = array();
422                        }
423                        foreach($langs as $lang)
424                        {
425                                //echo '<br>Working on: ' . $lang;
426                                $addlang = False;
427                                if ($upgrademethod == 'addonlynew')
428                                {
429                                        //echo "<br>Test: addonlynew - select count(*) from phpgw_lang where lang='".$lang."'";
430                                        $this->db->query("SELECT COUNT(*) FROM phpgw_lang WHERE lang='".$lang."'",__LINE__,__FILE__);
431                                        $this->db->next_record();
432
433                                        if ($this->db->f(0) == 0)
434                                        {
435                                                //echo '<br>Test: addonlynew - True';
436                                                $addlang = True;
437                                        }
438                                }
439                                if ($addlang && $upgrademethod == 'addonlynew' || $upgrademethod != 'addonlynew')
440                                {
441                                        //echo '<br>Test: loop above file()';
442                                        if (!is_object($GLOBALS['phpgw_setup']))
443                                        {
444                                                $GLOBALS['phpgw_setup'] = CreateObject('phpgwapi.setup');
445                                                $GLOBALS['phpgw_setup']->db = $this->db;
446                                        }
447                                        $setup_info = $GLOBALS['phpgw_setup']->detection->get_versions();
448                                        $setup_info = $GLOBALS['phpgw_setup']->detection->get_db_versions($setup_info);
449                                        $raw = array();
450                                        $apps = $only_app ? array($only_app) : array_keys($setup_info);
451                                        // Visit each app/setup dir, look for a phpgw_lang file
452                                        foreach($apps as $app)
453                                        {
454                                                $appfile = PHPGW_SERVER_ROOT . SEP . $app . SEP . 'setup' . SEP . 'phpgw_' . strtolower($lang) . '.lang';
455                                                //echo '<br>Checking in: ' . $app['name'];
456                                                if($GLOBALS['phpgw_setup']->app_registered($app) && file_exists($appfile))
457                                                {
458                                                        //echo '<br>Including: ' . $appfile;
459                                                        $lines = file($appfile);
460                                                        foreach($lines as $line)
461                                                        {
462                                                                // explode with "\t" and removing "\n" with str_replace, needed to work with mbstring.overload=7
463                                                                list($message_id,$app_name,,$content) = $_f_buffer = explode("\t",$line);
464                                                                $content=str_replace(array("\n","\r"),'',$content);
465
466                                                                if( count($_f_buffer) != 4 )
467                                                                {
468                                                                        $line_display = str_replace(array("\t","\n"),
469                                                                                array("<font color='red'><b>\\t</b></font>","<font color='red'><b>\\n</b></font>"), $line);
470                                                                        $this->line_rejected[] = array(
471                                                                                'appfile' => $appfile,
472                                                                                'line'    => $line_display,
473                                                                        );
474                                                                }
475                                                                $message_id = substr(strtolower(chop($message_id)),0,MAX_MESSAGE_ID_LENGTH);
476                                                                $app_name = chop($app_name);
477                                                                $raw[$app_name][$message_id] = $content;
478                                                        }
479                                                        $GLOBALS['phpgw_info']['server']['lang_ctimes'][$lang][$app] = filectime($appfile);
480                                                }
481                                        }
482                                        $charset = strtolower(@$raw['common']['charset'] ? $raw['common']['charset'] : $this->charset($lang));
483                                        //echo "<p>lang='$lang', charset='$charset', system_charset='$this->system_charset')</p>\n";
484                                        //echo "<p>raw($lang)=<pre>".print_r($raw,True)."</pre>\n";
485                                        foreach($raw as $app_name => $ids)
486                                        {
487                                                $app_name = $this->db->db_addslashes($app_name);
488
489                                                foreach($ids as $message_id => $content)
490                                                {
491                                                        if ($this->system_charset)
492                                                        {
493                                                                $content = $this->convert($content,$charset,$this->system_charset);
494                                                        }
495                                                        $message_id = $this->db->db_addslashes($message_id);
496                                                        $content = $this->db->db_addslashes($content);
497
498                                                        $addit = False;
499                                                        //echo '<br>APPNAME:' . $app_name . ' PHRASE:' . $message_id;
500                                                        if ($upgrademethod == 'addmissing')
501                                                        {
502                                                                //echo '<br>Test: addmissing';
503                                                                $this->db->query("SELECT content,CASE WHEN app_name IN ('common') then 1 else 0 END AS in_api FROM phpgw_lang WHERE message_id='$message_id' AND lang='$lang' AND (app_name='$app_name' OR app_name='common') ORDER BY in_api DESC",__LINE__,__FILE__);
504
505                                                                if (!($row = $this->db->row(True)))
506                                                                {
507                                                                        $addit = True;
508                                                                }
509                                                                else
510                                                                {
511                                                                        if ($row['in_api'])             // same phrase is in the api
512                                                                        {
513                                                                                $addit = $row['content'] != $content;   // only add if not identical
514                                                                        }
515                                                                        $row2 = $this->db->row(True);
516                                                                        if (!$row['in_api'] || $app_name=='common' || $row2)    // phrase is alread in the db
517                                                                        {
518                                                                                $addit = $content != ($row2 ? $row2['content'] : $row['content']);
519                                                                                if ($addit)     // if we want to add/update it ==> delete it
520                                                                                {
521                                                                                        $this->db->query($q="DELETE FROM phpgw_lang WHERE message_id='$message_id' AND lang='$lang' AND app_name='$app_name'",__LINE__,__FILE__);
522                                                                                }
523                                                                        }
524                                                                }
525                                                        }
526
527                                                        if ($addit || $upgrademethod == 'addonlynew' || $upgrademethod == 'dumpold')
528                                                        {
529                                                                if($message_id && $content)
530                                                                {
531                                                                        //echo "<br>adding - insert into phpgw_lang values ('$message_id','$app_name','$lang','$content')";
532                                                                        $result = $this->db->query("INSERT INTO phpgw_lang (message_id,app_name,lang,content) VALUES('$message_id','$app_name','$lang','$content')",__LINE__,__FILE__);
533                                                                        if ((int)$result <= 0)
534                                                                        {
535                                                                                echo "<br>Error inserting record: phpgw_lang values ('$message_id','$app_name','$lang','$content')";
536                                                                        }
537                                                                }
538                                                        }
539                                                }
540                                        }
541                                }
542                        }
543                        $this->db->transaction_commit();
544
545                        // update the ctimes of the installed langsfiles for the autoloading of the lang-files
546                        //
547                        $config =  CreateObject('phpgwapi.config.save_value');
548                        $config->save_value('lang_ctimes',$GLOBALS['phpgw_info']['server']['lang_ctimes'],'phpgwapi');
549                }
550
551                /*!
552                @function autolaod_changed_langfiles
553                @abstract re-loads all (!) langfiles if one langfile for the an app and the language of the user has changed
554                */
555                function autoload_changed_langfiles()
556                {
557                        //echo "<h1>check_langs()</h1>\n";
558                        if ($GLOBALS['phpgw_info']['server']['lang_ctimes'] && !is_array($GLOBALS['phpgw_info']['server']['lang_ctimes']))
559                        {
560                                $GLOBALS['phpgw_info']['server']['lang_ctimes'] = unserialize($GLOBALS['phpgw_info']['server']['lang_ctimes']);
561                        }
562                        //_debug_array($GLOBALS['phpgw_info']['server']['lang_ctimes']);
563
564                        $lang = $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'];
565                        $apps = $GLOBALS['phpgw_info']['user']['apps'];
566                        $apps['phpgwapi'] = True;       // check the api too
567                        foreach($apps as $app => $data)
568                        {
569                                $fname = PHPGW_SERVER_ROOT . "/$app/setup/phpgw_$lang.lang";
570
571                                if (file_exists($fname))
572                                {
573                                        $ctime = filectime($fname);
574                                        /* This is done to avoid string offset error at least in php5 */
575                                        $tmp = $GLOBALS['phpgw_info']['server']['lang_ctimes'][$lang];
576                                        $ltime = (int)$tmp[$app];
577                                        unset($tmp);
578                                        //echo "checking lang='$lang', app='$app', ctime='$ctime', ltime='$ltime'<br>\n";
579
580                                        if ($ctime != $ltime)
581                                        {
582                                                // update all langs
583                                                $installed = $this->get_installed_langs();
584                                                //echo "<p>install_langs(".print_r($installed,True).")</p>\n";
585                                                $this->install_langs($installed ? array_keys($installed) : array());
586                                                break;
587                                        }
588                                }
589                        }
590                }
591
592                /* Following functions are called for app (un)install */
593
594                /*!
595                @function get_langs
596                @abstract return array of installed languages, e.g. array('de','en')
597                */
598                function get_langs($DEBUG=False)
599                {
600                        if($DEBUG)
601                        {
602                                echo '<br>get_langs(): checking db...' . "\n";
603                        }
604                        if (!$this->langs)
605                        {
606                                $this->get_installed_langs();
607                        }
608                        return $this->langs ? array_keys($this->langs) : array();
609                }
610
611                /*!
612                @function drop_langs
613                @abstract delete all lang entries for an application, return True if langs were found
614                @param $appname app_name whose translations you want to delete
615                */
616                function drop_langs($appname,$DEBUG=False)
617                {
618                        if($DEBUG)
619                        {
620                                echo '<br>drop_langs(): Working on: ' . $appname;
621                        }
622                        $this->db->query("SELECT COUNT(message_id) FROM phpgw_lang WHERE app_name='$appname'",__LINE__,__FILE__);
623                        $this->db->next_record();
624                        if($this->db->f(0))
625                        {
626                                $this->db->query("DELETE FROM phpgw_lang WHERE app_name='$appname'",__LINE__,__FILE__);
627                                return True;
628                        }
629                        return False;
630                }
631
632                /*!
633                @function add_langs
634                @abstract process an application's lang files, calling get_langs() to see what langs the admin installed already
635                @param $appname app_name of application to process
636                */
637                function add_langs($appname,$DEBUG=False,$force_langs=False)
638                {
639                        $langs = $this->get_langs($DEBUG);
640                        if(is_array($force_langs))
641                        {
642                                foreach($force_langs as $lang)
643                                {
644                                        if (!in_array($lang,$langs))
645                                        {
646                                                $langs[] = $lang;
647                                        }
648                                }
649                        }
650
651                        if($DEBUG)
652                        {
653                                echo '<br>add_langs(): chose these langs: ';
654                                _debug_array($langs);
655                        }
656
657                        $this->install_langs($langs,'addmissing',$appname);
658                }
659        }
Note: See TracBrowser for help on using the repository browser.