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