1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare API - Translation class for phpgw lang files * |
---|
4 | * This file written by Miles Lott <milosch@groupwhere.org> * |
---|
5 | * and Dan Kuykendall <seek3r@phpgroupware.org> * |
---|
6 | * Handles multi-language support using flat files * |
---|
7 | * -------------------------------------------------------------------------* |
---|
8 | * This library is part of the eGroupWare API * |
---|
9 | * http://www.egroupware.org/api * |
---|
10 | * ------------------------------------------------------------------------ * |
---|
11 | * This library is free software; you can redistribute it and/or modify it * |
---|
12 | * under the terms of the GNU Lesser General Public License as published by * |
---|
13 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
14 | * or any later version. * |
---|
15 | * This library is distributed in the hope that it will be useful, but * |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
18 | * See the GNU Lesser General Public License for more details. * |
---|
19 | * You should have received a copy of the GNU Lesser General Public License * |
---|
20 | * along with this library; if not, write to the Free Software Foundation, * |
---|
21 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
22 | \**************************************************************************/ |
---|
23 | |
---|
24 | |
---|
25 | if (!defined('MAX_MESSAGE_ID_LENGTH')) |
---|
26 | { |
---|
27 | define('MAX_MESSAGE_ID_LENGTH',230); |
---|
28 | } |
---|
29 | |
---|
30 | class setup_translation |
---|
31 | { |
---|
32 | var $langarray = array(); |
---|
33 | |
---|
34 | /*! |
---|
35 | @function setup_lang |
---|
36 | @abstract constructor for the class, loads all phrases into langarray |
---|
37 | @param $lang user lang variable (defaults to en) |
---|
38 | */ |
---|
39 | function setup_translation() |
---|
40 | { |
---|
41 | $ConfigLang = get_var('ConfigLang',Array('POST','COOKIE')); |
---|
42 | |
---|
43 | if(!$ConfigLang) |
---|
44 | { |
---|
45 | $lang = 'en'; |
---|
46 | } |
---|
47 | else |
---|
48 | { |
---|
49 | $lang = $ConfigLang; |
---|
50 | } |
---|
51 | |
---|
52 | $fn = '.' . SEP . 'lang' . SEP . 'phpgw_' . $lang . '.lang'; |
---|
53 | if (!file_exists($fn)) |
---|
54 | { |
---|
55 | $fn = '.' . SEP . 'lang' . SEP . 'phpgw_en.lang'; |
---|
56 | } |
---|
57 | if (file_exists($fn)) |
---|
58 | { |
---|
59 | $fp = fopen($fn,'r'); |
---|
60 | while ($data = fgets($fp,8000)) |
---|
61 | { |
---|
62 | // explode with "\t" and removing "\n" with str_replace, needed to work with mbstring.overload=7 |
---|
63 | list($message_id,,,$content) = explode("\t",$data); |
---|
64 | $this->langarray[strtolower(trim($message_id))] = str_replace("\n",'',$content); |
---|
65 | } |
---|
66 | fclose($fp); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | /*! |
---|
71 | @function translate |
---|
72 | @abstract Translate phrase to user selected lang |
---|
73 | @param $key phrase to translate |
---|
74 | @param $vars vars sent to lang function, passed to us |
---|
75 | */ |
---|
76 | function translate($key, $vars=False) |
---|
77 | { |
---|
78 | $ret = $key.'*'; |
---|
79 | $key = strtolower(trim($key)); |
---|
80 | if (isset($this->langarray[$key])) |
---|
81 | { |
---|
82 | $ret = $this->langarray[$key]; |
---|
83 | } |
---|
84 | if (is_array($vars)) |
---|
85 | { |
---|
86 | foreach($vars as $n => $var) |
---|
87 | { |
---|
88 | $ret = preg_replace( '/%'.($n+1).'/', $var, $ret ); |
---|
89 | } |
---|
90 | } |
---|
91 | return $ret; |
---|
92 | } |
---|
93 | |
---|
94 | // the following functions have been moved to phpgwapi/tanslation_sql |
---|
95 | |
---|
96 | function setup_translation_sql() |
---|
97 | { |
---|
98 | if (!is_object($this->sql)) |
---|
99 | { |
---|
100 | include_once(PHPGW_API_INC.'/class.translation_sql.inc.php'); |
---|
101 | $this->sql = new translation; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | function get_langs($DEBUG=False) |
---|
106 | { |
---|
107 | $this->setup_translation_sql(); |
---|
108 | return $this->sql->get_langs($DEBUG); |
---|
109 | } |
---|
110 | |
---|
111 | function drop_langs($appname,$DEBUG=False) |
---|
112 | { |
---|
113 | $this->setup_translation_sql(); |
---|
114 | return $this->sql->drop_langs($appname,$DEBUG); |
---|
115 | } |
---|
116 | |
---|
117 | function add_langs($appname,$DEBUG=False,$force_langs=False) |
---|
118 | { |
---|
119 | $this->setup_translation_sql(); |
---|
120 | return $this->sql->add_langs($appname,$DEBUG,$force_langs); |
---|
121 | } |
---|
122 | } |
---|
123 | ?> |
---|