Converting to GPL
[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 * Localization table
54 * @var array
55 */
56 var $localtable = array();
57
58 /**
59 * The lex lookup table
60 * @var array
61 */
62 var $lextable = array();
63
64 /**
65 * Initializes the localization system with a table
66 *
67 * @param array Localization table
68 */
69 function init_with_table($table)
70 {
71 $this->localtable = $table;
72 }
73
74 /**
75 * Returns a localized string from the table
76 *
77 * @param str Text to localize
78 *
79 * @return str Localized string
80 */
81 function string($key)
82 {
83 if (defined('ISSO_LOCALIZE_DEBUG'))
84 {
85 return '[@&quot;' . $key . '&quot;]';
86 }
87
88 if ($this->localtable["$key"])
89 {
90 return $this->localtable["$key"];
91 }
92
93 return $key;
94 }
95
96 /**
97 * Returns a value from the lex table for a specific code
98 *
99 * @param str Lex code
100 *
101 * @return str Localized string
102 */
103 function getlex($code)
104 {
105 if (defined('ISSO_LOCALIZE_DEBUG'))
106 {
107 return '&[@&quot;' . $code . '&quot;]';
108 }
109
110 if (isset($this->lextable["$code"]))
111 {
112 return $this->lextable["$code"];
113 }
114
115 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR);
116 }
117
118 /**
119 * Sets a value in the lex table for easy access of strings
120 * that are commonly used
121 *
122 * @param str Lex code
123 * @param str Text equiv
124 */
125 function setlex($code, $value)
126 {
127 if (isset($this->lextable["$code"]))
128 {
129 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR);
130 }
131
132 $this->lextable["$code"] = $value;
133 }
134 }
135
136 /*=====================================================================*\
137 || ###################################################################
138 || # $HeadURL$
139 || # $Id$
140 || ###################################################################
141 \*=====================================================================*/
142 ?>