2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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.
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
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 \*=====================================================================*/
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.
41 * ISSO_LOCALIZE_DEBUG - Wrap all strings in markup to show that it
45 * @copyright Copyright ©2002 - [#]year[#], Blue Static
53 * Framework registry object
56 private $registry = null
;
62 private $localtable = array();
65 * The lex lookup table
68 private $lextable = array();
70 // ###################################################################
74 function __construct(&$registry)
76 $this->registry
=& $registry;
79 // ###################################################################
83 function Localize(&$registry)
85 $this->__construct($registry);
88 // ###################################################################
90 * Initializes the localization system with a table
94 * @param array Localization table
96 function init_with_table($table)
98 $this->localtable
= $table;
101 // ###################################################################
103 * Returns a localized string from the table
107 * @param string Text to localize
109 * @return string Localized string
111 function string($key)
113 if (defined('ISSO_LOCALIZE_DEBUG'))
115 return '[@"' . $key . '"]';
118 if (isset($this->localtable
["$key"]))
120 return $this->localtable
["$key"];
126 // ###################################################################
128 * Returns a value from the lex table for a specific code
132 * @param string Lex code
134 * @return string Localized string
136 function getlex($code)
138 if (defined('ISSO_LOCALIZE_DEBUG'))
140 return '&[@"' . $code . '"]';
143 if (isset($this->lextable
["$code"]))
145 return $this->lextable
["$code"];
148 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR
);
151 // ###################################################################
153 * Sets a value in the lex table for easy access of strings
154 * that are commonly used
158 * @param string Lex code
159 * @param string Text equiv
161 function setlex($code, $value)
163 if (isset($this->lextable
["$code"]))
165 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR
);
168 $this->lextable
["$code"] = $value;
172 /*=====================================================================*\
173 || ###################################################################
176 || ###################################################################
177 \*=====================================================================*/