Merging changes back to trunk from r262
[isso.git] / localize.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 /**
14 * Localization system
15 * localize.php
16 *
17 * @package ISSO
18 */
19
20 $OBJECT = 'Localization System';
21 $CLASS = 'Localize';
22 $OBJ = 'lang';
23
24 /**
25 * Localization System
26 *
27 * This framework handles localization. Localization in new ISSO
28 * applications is done through this framework. Nearly all strings
29 * are passed to the string function, which looks up the string in
30 * a .strings.xml file during runtime. Before release, mkstrings
31 * creates the .strings.xml file for translators. Common strings
32 * can be accessed through the get lex function which calls a string
33 * based on unique identifier; this is useful for commonly used strings.
34 *
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
37 * @version $Revision$
38 * @package ISSO
39 *
40 */
41 class Localize
42 {
43 /**
44 * Localization table
45 * @var array
46 */
47 var $localtable = array();
48
49 /**
50 * The lex lookup table
51 * @var array
52 */
53 var $lextable = array();
54
55 /**
56 * Initializes the localization system with a table
57 *
58 * @param array Localization table
59 */
60 function init_with_table($table)
61 {
62 $this->localtable = $table;
63 }
64
65 /**
66 * Returns a localized string from the table
67 *
68 * @param str Text to localize
69 *
70 * @return str Localized string
71 */
72 function string($key)
73 {
74 if (defined('ISSO_LOCALIZE_DEBUG'))
75 {
76 return '[@&quot;' . $key . '&quot;]';
77 }
78
79 if ($this->localtable["$key"])
80 {
81 return $this->localtable["$key"];
82 }
83
84 return $key;
85 }
86
87 /**
88 * Returns a value from the lex table for a specific code
89 *
90 * @param str Lex code
91 *
92 * @return str Localized string
93 */
94 function getlex($code)
95 {
96 if (defined('ISSO_LOCALIZE_DEBUG'))
97 {
98 return '&[@&quot;' . $code . '&quot;]';
99 }
100
101 if (isset($this->lextable["$code"]))
102 {
103 return $this->lextable["$code"];
104 }
105
106 trigger_error('Lex code `' . $code . '` did not appear in the lex table', E_USER_ERROR);
107 }
108
109 /**
110 * Sets a value in the lex table for easy access of strings
111 * that are commonly used
112 *
113 * @param str Lex code
114 * @param str Text equiv
115 */
116 function setlex($code, $value)
117 {
118 if (isset($this->lextable["$code"]))
119 {
120 trigger_error('Cannot set lex `' . $code . '` : value already exists', E_USER_ERROR);
121 }
122
123 $this->lextable["$code"] = $value;
124 }
125 }
126
127 /*=====================================================================*\
128 || ###################################################################
129 || # $HeadURL$
130 || # $Id$
131 || ###################################################################
132 \*=====================================================================*/
133 ?>