Removing the PHP4 constructors
[isso.git] / localize.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Localization system
24 * localize.php
25 *
26 * @package ISSO
27 */
28
29 /**
30 * Localization System
31 *
32 * This framework handles localization. Localization in new ISSO
33 * applications is done through this framework. Nearly all strings
34 * are passed to the string function, which looks up the string in
35 * a .strings.xml file during runtime. Before release, mkstrings
36 * creates the .strings.xml file for translators. Common strings
37 * can be accessed through the get lex function which calls a string
38 * based on unique identifier; this is useful for commonly used strings.
39 *
40 * Constants:
41 * ISSO_LOCALIZE_DEBUG - Wrap all strings in markup to show that it
42 * has been localized
43 *
44 * @author Blue Static
45 * @copyright Copyright ©2002 - [#]year[#], Blue Static
46 * @version $Revision$
47 * @package ISSO
48 *
49 */
50 class Localize
51 {
52 /**
53 * Framework registry object
54 * @var object
55 */
56 private $registry = null;
57
58 /**
59 * Localization table
60 * @var array
61 */
62 private $localtable = array();
63
64 /**
65 * The lex lookup table
66 * @var array
67 */
68 private $lextable = array();
69
70 // ###################################################################
71 /**
72 * Constructor
73 */
74 function __construct(&$registry)
75 {
76 $this->registry =& $registry;
77 }
78
79 // ###################################################################
80 /**
81 * Initializes the localization system with a table
82 *
83 * @access public
84 *
85 * @param array Localization table
86 */
87 function init_with_table($table)
88 {
89 $this->localtable = $table;
90 }
91
92 // ###################################################################
93 /**
94 * Returns a localized string from the table
95 *
96 * @access public
97 *
98 * @param string Text to localize
99 *
100 * @return string Localized string
101 */
102 function string($key)
103 {
104 if (defined('ISSO_LOCALIZE_DEBUG'))
105 {
106 return '[@&quot;' . $key . '&quot;]';
107 }
108
109 if (isset($this->localtable["$key"]))
110 {
111 return $this->localtable["$key"];
112 }
113
114 return $key;
115 }
116
117 // ###################################################################
118 /**
119 * Returns a value from the lex table for a specific code
120 *
121 * @access public
122 *
123 * @param string Lex code
124 *
125 * @return string Localized string
126 */
127 function getlex($code)
128 {
129 if (defined('ISSO_LOCALIZE_DEBUG'))
130 {
131 return '&[@&quot;' . $code . '&quot;]';
132 }
133
134 if (isset($this->lextable["$code"]))
135 {
136 return $this->lextable["$code"];
137 }
138
139 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR);
140 }
141
142 // ###################################################################
143 /**
144 * Sets a value in the lex table for easy access of strings
145 * that are commonly used
146 *
147 * @access public
148 *
149 * @param string Lex code
150 * @param string Text equiv
151 */
152 function setlex($code, $value)
153 {
154 if (isset($this->lextable["$code"]))
155 {
156 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR);
157 }
158
159 $this->lextable["$code"] = $value;
160 }
161 }
162
163 /*=====================================================================*\
164 || ###################################################################
165 || # $HeadURL$
166 || # $Id$
167 || ###################################################################
168 \*=====================================================================*/
169 ?>