]>
src.bluestatic.org Git - isso.git/blob - localize.php
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 public function __construct(&$registry)
76 $this->registry
=& $registry;
79 // ###################################################################
81 * Initializes the localization system with a table
83 * @param array Localization table
85 public function init_with_table($table)
87 $this->localtable
= $table;
90 // ###################################################################
92 * Returns a localized string from the table
94 * @param string Text to localize
96 * @return string Localized string
98 public function string($key)
100 if (defined('ISSO_LOCALIZE_DEBUG'))
102 return '[@"' . $key . '"]';
105 if (isset($this->localtable
["$key"]))
107 return $this->localtable["$key"];
113 // ###################################################################
115 * Returns a value from the lex table for a specific code
117 * @param string Lex code
119 * @return string Localized string
121 public function getlex($code)
123 if (defined('ISSO_LOCALIZE_DEBUG'))
125 return '&[@"' . $code . '"]';
128 if (isset($this->lextable
["$code"]))
130 return $this->lextable["$code"];
133 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR
);
136 // ###################################################################
138 * Sets a value in the lex table for easy access of strings
139 * that are commonly used
141 * @param string Lex code
142 * @param string Text equiv
144 public function setlex($code, $value)
146 if (isset($this->lextable
["$code"]))
148 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR);
151 $this->lextable["$code"] = $value;
155 /*=====================================================================*\
156 || ###################################################################
159 || ###################################################################
160 \*=====================================================================*/