1 | <?php |
---|
2 | /* |
---|
3 | File: xajaxLanguageManager.inc.php |
---|
4 | |
---|
5 | Contains the code that manages the inclusion of alternate language support |
---|
6 | files; so debug and error messages can be shown in a language other than |
---|
7 | the default (english) language. |
---|
8 | |
---|
9 | Title: xajaxLanguageManager class |
---|
10 | |
---|
11 | Please see <copyright.inc.php> for a detailed description, copyright |
---|
12 | and license information. |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | @package xajax |
---|
17 | @version $Id: xajaxLanguageManager.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $ |
---|
18 | @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson |
---|
19 | @license http://www.xajaxproject.org/bsd_license.txt BSD License |
---|
20 | */ |
---|
21 | |
---|
22 | /* |
---|
23 | Class: xajaxLanguageManager |
---|
24 | |
---|
25 | This class contains the default language (english) and the code used to supply |
---|
26 | debug and error messages upon request; as well as the code used to load alternate |
---|
27 | language text as requested via the <xajax::configure> function. |
---|
28 | */ |
---|
29 | class xajaxLanguageManager |
---|
30 | { |
---|
31 | /* |
---|
32 | Array: aMessages |
---|
33 | |
---|
34 | An array of the currently registered languages. |
---|
35 | */ |
---|
36 | var $aMessages; |
---|
37 | |
---|
38 | /* |
---|
39 | String: sLanguage |
---|
40 | |
---|
41 | The currently configured language. |
---|
42 | */ |
---|
43 | var $sLanguage; |
---|
44 | |
---|
45 | /* |
---|
46 | Function: xajaxLanguageManager |
---|
47 | |
---|
48 | Construct and initialize the one and only xajax language manager object. |
---|
49 | */ |
---|
50 | function xajaxLanguageManager() |
---|
51 | { |
---|
52 | $this->aMessages = array(); |
---|
53 | |
---|
54 | $this->aMessages['en'] = array( |
---|
55 | 'LOGHDR:01' => '** xajax Error Log - ', |
---|
56 | 'LOGHDR:02' => " **\n", |
---|
57 | 'LOGHDR:03' => "\n\n\n", |
---|
58 | 'LOGERR:01' => "** Logging Error **\n\nxajax was unable to write to the error log file:\n", |
---|
59 | 'LOGMSG:01' => "** PHP Error Messages: **", |
---|
60 | 'CMPRSJS:RDERR:01' => 'The xajax uncompressed Javascript file could not be found in the <b>', |
---|
61 | 'CMPRSJS:RDERR:02' => '</b> folder. Error ', |
---|
62 | 'CMPRSJS:WTERR:01' => 'The xajax compressed javascript file could not be written in the <b>', |
---|
63 | 'CMPRSJS:WTERR:02' => '</b> folder. Error ', |
---|
64 | 'CMPRSPHP:WTERR:01' => 'The xajax compressed file <b>', |
---|
65 | 'CMPRSPHP:WTERR:02' => '</b> could not be written to. Error ', |
---|
66 | 'CMPRSAIO:WTERR:01' => 'The xajax compressed file <b>', |
---|
67 | 'CMPRSAIO:WTERR:02' => '/xajaxAIO.inc.php</b> could not be written to. Error ', |
---|
68 | 'DTCTURI:01' => 'xajax Error: xajax failed to automatically identify your Request URI.', |
---|
69 | 'DTCTURI:02' => 'Please set the Request URI explicitly when you instantiate the xajax object.', |
---|
70 | 'ARGMGR:ERR:01' => 'Malformed object argument received: ', |
---|
71 | 'ARGMGR:ERR:02' => ' <==> ', |
---|
72 | 'ARGMGR:ERR:03' => 'The incoming xajax data could not be converted from UTF-8', |
---|
73 | 'XJXCTL:IAERR:01' => 'Invalid attribute [', |
---|
74 | 'XJXCTL:IAERR:02' => '] for element [', |
---|
75 | 'XJXCTL:IAERR:03' => '].', |
---|
76 | 'XJXCTL:IRERR:01' => 'Invalid request object passed to xajaxControl::setEvent', |
---|
77 | 'XJXCTL:IEERR:01' => 'Invalid attribute (event name) [', |
---|
78 | 'XJXCTL:IEERR:02' => '] for element [', |
---|
79 | 'XJXCTL:IEERR:03' => '].', |
---|
80 | 'XJXCTL:MAERR:01' => 'Missing required attribute [', |
---|
81 | 'XJXCTL:MAERR:02' => '] for element [', |
---|
82 | 'XJXCTL:MAERR:03' => '].', |
---|
83 | 'XJXCTL:IETERR:01' => "Invalid end tag designation; should be forbidden or optional.\n", |
---|
84 | 'XJXCTL:ICERR:01' => "Invalid class specified for html control; should be %inline, %block or %flow.\n", |
---|
85 | 'XJXCTL:ICLERR:01' => 'Invalid control passed to addChild; should be derived from xajaxControl.', |
---|
86 | 'XJXCTL:ICLERR:02' => 'Invalid control passed to addChild [', |
---|
87 | 'XJXCTL:ICLERR:03' => '] for element [', |
---|
88 | 'XJXCTL:ICLERR:04' => "].\n", |
---|
89 | 'XJXCTL:ICHERR:01' => 'Invalid parameter passed to xajaxControl::addChildren; should be array of xajaxControl objects', |
---|
90 | 'XJXCTL:MRAERR:01' => 'Missing required attribute [', |
---|
91 | 'XJXCTL:MRAERR:02' => '] for element [', |
---|
92 | 'XJXCTL:MRAERR:03' => '].', |
---|
93 | 'XJXPLG:GNERR:01' => 'Response plugin should override the getName function.', |
---|
94 | 'XJXPLG:PERR:01' => 'Response plugin should override the process function.', |
---|
95 | 'XJXPM:IPLGERR:01' => 'Attempt to register invalid plugin: ', |
---|
96 | 'XJXPM:IPLGERR:02' => ' should be derived from xajaxRequestPlugin or xajaxResponsePlugin.', |
---|
97 | 'XJXPM:MRMERR:01' => 'Failed to locate registration method for the following: ', |
---|
98 | 'XJXRSP:EDERR:01' => 'Passing character encoding to the xajaxResponse constructor is deprecated, instead use $xajax->configure("characterEncoding", ...);', |
---|
99 | 'XJXRSP:MPERR:01' => 'Invalid or missing plugin name detected in call to xajaxResponse::plugin', |
---|
100 | 'XJXRSP:CPERR:01' => "The \$sType parameter of addCreate has been deprecated. Use the addCreateInput() method instead.", |
---|
101 | 'XJXRSP:LCERR:01' => "The xajax response object could not load commands as the data provided was not a valid array.", |
---|
102 | 'XJXRSP:AKERR:01' => 'Invalid tag name encoded in array.', |
---|
103 | 'XJXRSP:IEAERR:01' => 'Improperly encoded array.', |
---|
104 | 'XJXRSP:NEAERR:01' => 'Non-encoded array detected.', |
---|
105 | 'XJXRSP:MBEERR:01' => 'The xajax response output could not be converted to HTML entities because the mb_convert_encoding function is not available', |
---|
106 | 'XJXRSP:MXRTERR' => 'Error: Cannot mix types in a single response.', |
---|
107 | 'XJXRSP:MXCTERR' => 'Error: Cannot mix content types in a single response.', |
---|
108 | 'XJXRSP:MXCEERR' => 'Error: Cannot mix character encodings in a single response.', |
---|
109 | 'XJXRSP:MXOEERR' => 'Error: Cannot mix output entities (true/false) in a single response.', |
---|
110 | 'XJXRM:IRERR' => 'An invalid response was returned while processing this request.', |
---|
111 | 'XJXRM:MXRTERR' => 'Error: You cannot mix response types while processing a single request: ' |
---|
112 | ); |
---|
113 | |
---|
114 | $this->sLanguage = 'en'; |
---|
115 | } |
---|
116 | |
---|
117 | /* |
---|
118 | Function: getInstance |
---|
119 | |
---|
120 | Implements the singleton pattern: provides a single instance of the xajax |
---|
121 | language manager object to all object which request it. |
---|
122 | */ |
---|
123 | function &getInstance() |
---|
124 | { |
---|
125 | static $obj; |
---|
126 | if (!$obj) { |
---|
127 | $obj = new xajaxLanguageManager(); |
---|
128 | } |
---|
129 | return $obj; |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | Function: configure |
---|
134 | |
---|
135 | Called by the main xajax object as configuration options are set. See also: |
---|
136 | <xajax::configure>. The <xajaxLanguageManager> tracks the following configuration |
---|
137 | options: |
---|
138 | |
---|
139 | - language (string, default 'en'): The currently selected language. |
---|
140 | */ |
---|
141 | function configure($sName, $mValue) |
---|
142 | { |
---|
143 | if ('language' == $sName) { |
---|
144 | if ($mValue !== $this->sLanguage) { |
---|
145 | $sFolder = dirname(__FILE__); |
---|
146 | require $sFolder . '/xajax_lang_' . $mValue . '.inc.php'; |
---|
147 | $this->sLanguage = $mValue; |
---|
148 | } |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | /* |
---|
153 | Function: register |
---|
154 | |
---|
155 | Called to register an array of alternate language messages. |
---|
156 | |
---|
157 | sLanguage - (string) the character code which represents the language being registered. |
---|
158 | aMessages - (array) the array of translated debug and error messages |
---|
159 | */ |
---|
160 | function register($sLanguage, $aMessages) { |
---|
161 | $this->aMessages[$sLanguage] = $aMessages; |
---|
162 | } |
---|
163 | |
---|
164 | /* |
---|
165 | Function: getText |
---|
166 | |
---|
167 | Called by the main xajax object and other objects during the initial page generation |
---|
168 | or request processing phase to obtain language specific debug and error messages. |
---|
169 | |
---|
170 | sMessage - (string): A code indicating the message text being requested. |
---|
171 | */ |
---|
172 | function getText($sMessage) |
---|
173 | { |
---|
174 | if (isset($this->aMessages[$this->sLanguage])) |
---|
175 | if (isset($this->aMessages[$this->sLanguage][$sMessage])) |
---|
176 | return $this->aMessages[$this->sLanguage][$sMessage]; |
---|
177 | |
---|
178 | return '(Unknown language or message identifier)' |
---|
179 | . $this->sLanguage |
---|
180 | . '::' |
---|
181 | . $sMessage; |
---|
182 | } |
---|
183 | } |
---|