Remove unused class call
[isso.git] / localize.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 Iris Studios, Inc.
45 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
46 * @version $Revision$
47 * @package ISSO
48 *
49 */
50 class Localize
51 {
52 /**
53 * Framework registry object
54 * @var object
55 * @access private
56 */
57 var $registry = null;
58
59 /**
60 * Localization table
61 * @var array
62 * @access private
63 */
64 var $localtable = array();
65
66 /**
67 * The lex lookup table
68 * @var array
69 * @access private
70 */
71 var $lextable = array();
72
73 // ###################################################################
74 /**
75 * Constructor
76 */
77 function __construct(&$registry)
78 {
79 $this->registry =& $registry;
80 }
81
82 // ###################################################################
83 /**
84 * (PHP 4) Constructor
85 */
86 function Localize(&$registry)
87 {
88 $this->__construct($registry);
89 }
90
91 // ###################################################################
92 /**
93 * Initializes the localization system with a table
94 *
95 * @access public
96 *
97 * @param array Localization table
98 */
99 function init_with_table($table)
100 {
101 $this->localtable = $table;
102 }
103
104 // ###################################################################
105 /**
106 * Returns a localized string from the table
107 *
108 * @access public
109 *
110 * @param string Text to localize
111 *
112 * @return string Localized string
113 */
114 function string($key)
115 {
116 if (defined('ISSO_LOCALIZE_DEBUG'))
117 {
118 return '[@&quot;' . $key . '&quot;]';
119 }
120
121 if (isset($this->localtable["$key"]))
122 {
123 return $this->localtable["$key"];
124 }
125
126 return $key;
127 }
128
129 // ###################################################################
130 /**
131 * Returns a value from the lex table for a specific code
132 *
133 * @access public
134 *
135 * @param string Lex code
136 *
137 * @return string Localized string
138 */
139 function getlex($code)
140 {
141 if (defined('ISSO_LOCALIZE_DEBUG'))
142 {
143 return '&[@&quot;' . $code . '&quot;]';
144 }
145
146 if (isset($this->lextable["$code"]))
147 {
148 return $this->lextable["$code"];
149 }
150
151 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR);
152 }
153
154 // ###################################################################
155 /**
156 * Sets a value in the lex table for easy access of strings
157 * that are commonly used
158 *
159 * @access public
160 *
161 * @param string Lex code
162 * @param string Text equiv
163 */
164 function setlex($code, $value)
165 {
166 if (isset($this->lextable["$code"]))
167 {
168 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR);
169 }
170
171 $this->lextable["$code"] = $value;
172 }
173 }
174
175 /*=====================================================================*\
176 || ###################################################################
177 || # $HeadURL$
178 || # $Id$
179 || ###################################################################
180 \*=====================================================================*/
181 ?>