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