Added registry connection plugs to the modules
[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 $OBJECT = 'Localization System';
30 $CLASS = 'Localize';
31 $OBJ = 'lang';
32
33 /**
34 * Localization System
35 *
36 * This framework handles localization. Localization in new ISSO
37 * applications is done through this framework. Nearly all strings
38 * are passed to the string function, which looks up the string in
39 * a .strings.xml file during runtime. Before release, a C tool
40 * creates the .strings.xml file for translators. Common strings
41 * can be accessed through the get lex function which calls a string
42 * based on unique identifier; this is useful for commonly used strings.
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 * Constructor
72 */
73 function Localize($registry)
74 {
75 $this->registry = $registry;
76 }
77
78 /**
79 * Initializes the localization system with a table
80 *
81 * @param array Localization table
82 */
83 function init_with_table($table)
84 {
85 $this->localtable = $table;
86 }
87
88 /**
89 * Returns a localized string from the table
90 *
91 * @param string Text to localize
92 *
93 * @return string Localized string
94 */
95 function string($key)
96 {
97 if (defined('ISSO_LOCALIZE_DEBUG'))
98 {
99 return '[@&quot;' . $key . '&quot;]';
100 }
101
102 if ($this->localtable["$key"])
103 {
104 return $this->localtable["$key"];
105 }
106
107 return $key;
108 }
109
110 /**
111 * Returns a value from the lex table for a specific code
112 *
113 * @param string Lex code
114 *
115 * @return string Localized string
116 */
117 function getlex($code)
118 {
119 if (defined('ISSO_LOCALIZE_DEBUG'))
120 {
121 return '&[@&quot;' . $code . '&quot;]';
122 }
123
124 if (isset($this->lextable["$code"]))
125 {
126 return $this->lextable["$code"];
127 }
128
129 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR);
130 }
131
132 /**
133 * Sets a value in the lex table for easy access of strings
134 * that are commonly used
135 *
136 * @param string Lex code
137 * @param string Text equiv
138 */
139 function setlex($code, $value)
140 {
141 if (isset($this->lextable["$code"]))
142 {
143 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR);
144 }
145
146 $this->lextable["$code"] = $value;
147 }
148 }
149
150 /*=====================================================================*\
151 || ###################################################################
152 || # $HeadURL$
153 || # $Id$
154 || ###################################################################
155 \*=====================================================================*/
156 ?>