]>
src.bluestatic.org Git - isso.git/blob - localize.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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
44 * @author Iris Studios, Inc.
45 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
53 * Framework registry object
64 var $localtable = array();
67 * The lex lookup table
71 var $lextable = array();
73 // ###################################################################
77 function __construct(&$registry)
79 $this->registry
=& $registry;
82 // ###################################################################
86 function Localize(&$registry)
88 $this->__construct($registry);
91 // ###################################################################
93 * Initializes the localization system with a table
97 * @param array Localization table
99 function init_with_table($table)
101 $this->localtable
= $table;
104 // ###################################################################
106 * Returns a localized string from the table
110 * @param string Text to localize
112 * @return string Localized string
114 function string($key)
116 if (defined('ISSO_LOCALIZE_DEBUG'))
118 return '[@"' . $key . '"]';
121 if (isset($this->localtable
["$key"]))
123 return $this->localtable["$key"];
129 // ###################################################################
131 * Returns a value from the lex table for a specific code
135 * @param string Lex code
137 * @return string Localized string
139 function getlex($code)
141 if (defined('ISSO_LOCALIZE_DEBUG'))
143 return '&[@"' . $code . '"]';
146 if (isset($this->lextable
["$code"]))
148 return $this->lextable["$code"];
151 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR
);
154 // ###################################################################
156 * Sets a value in the lex table for easy access of strings
157 * that are commonly used
161 * @param string Lex code
162 * @param string Text equiv
164 function setlex($code, $value)
166 if (isset($this->lextable
["$code"]))
168 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR);
171 $this->lextable["$code"] = $value;
175 /*=====================================================================*\
176 || ###################################################################
179 || ###################################################################
180 \*=====================================================================*/