59177427 |
1 | <?php |
1fd97780 |
2 | |
35586184 |
3 | /** |
d3bab52e |
4 | * SquirrelMail internationalization functions |
35586184 |
5 | * |
2ba706ef |
6 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This file contains variuos functions that are needed to do |
10 | * internationalization of SquirrelMail. |
11 | * |
12 | * Internally the output character set is used. Other characters are |
13 | * encoded using Unicode entities according to HTML 4.0. |
14 | * |
a8a1c36d |
15 | * @version $Id$ |
d6c32258 |
16 | * @package squirrelmail |
a8a1c36d |
17 | * @subpackage i18n |
35586184 |
18 | */ |
19 | |
d6c32258 |
20 | /** Everything uses global.php... */ |
961ca3d8 |
21 | require_once(SM_PATH . 'functions/global.php'); |
22 | |
d6c32258 |
23 | /** |
51468260 |
24 | * Converts string from given charset to charset, that can be displayed by user translation. |
25 | * |
26 | * Function by default returns html encoded strings, if translation uses different encoding. |
27 | * If Japanese translation is used - function returns string converted to euc-jp |
28 | * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string. |
29 | * If $charset is not supported - function returns unconverted string. |
62f7daa5 |
30 | * |
51468260 |
31 | * sanitizing of html tags is also done by this function. |
32 | * |
d6c32258 |
33 | * @param string $charset |
34 | * @param string $string Text to be decoded |
51468260 |
35 | * @return string decoded string |
d6c32258 |
36 | */ |
a2a7852b |
37 | function charset_decode ($charset, $string) { |
3ec81e63 |
38 | global $languages, $squirrelmail_language, $default_charset; |
f03f6ee7 |
39 | global $use_php_recode, $use_php_iconv, $aggressive_decoding; |
a2a7852b |
40 | |
3714db45 |
41 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
1bb86586 |
42 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { |
43 | $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string); |
6fbd125b |
44 | } |
b05c8961 |
45 | |
3ec81e63 |
46 | $charset = strtolower($charset); |
47 | |
48 | set_my_charset(); |
49 | |
50 | // Variables that allow to use functions without function_exist() calls |
edf2c0ba |
51 | if (! isset($use_php_recode) || $use_php_recode=="" ) { |
03db90bc |
52 | $use_php_recode=false; } |
edf2c0ba |
53 | if (! isset($use_php_iconv) || $use_php_iconv=="" ) { |
54 | $use_php_iconv=false; } |
3ec81e63 |
55 | |
56 | // Don't do conversion if charset is the same. |
57 | if ( $charset == strtolower($default_charset) ) |
58 | return htmlspecialchars($string); |
59 | |
60 | // catch iso-8859-8-i thing |
61 | if ( $charset == "iso-8859-8-i" ) |
62 | $charset = "iso-8859-8"; |
63 | |
64 | /* |
62f7daa5 |
65 | * Recode converts html special characters automatically if you use |
66 | * 'charset..html' decoding. There is no documented way to put -d option |
3ec81e63 |
67 | * into php recode function call. |
68 | */ |
69 | if ( $use_php_recode ) { |
70 | if ( $default_charset == "utf-8" ) { |
03db90bc |
71 | // other charsets can be converted to utf-8 without loss. |
72 | // and output string is smaller |
73 | $string = recode_string($charset . "..utf-8",$string); |
74 | return htmlspecialchars($string); |
3ec81e63 |
75 | } else { |
03db90bc |
76 | $string = recode_string($charset . "..html",$string); |
77 | // recode does not convert single quote, htmlspecialchars does. |
78 | $string = str_replace("'", ''', $string); |
79 | return $string; |
3ec81e63 |
80 | } |
81 | } |
82 | |
83 | // iconv functions does not have html target and can be used only with utf-8 |
84 | if ( $use_php_iconv && $default_charset=='utf-8') { |
85 | $string = iconv($charset,$default_charset,$string); |
86 | return htmlspecialchars($string); |
87 | } |
88 | |
89 | // If we don't use recode and iconv, we'll do it old way. |
90 | |
a2a7852b |
91 | /* All HTML special characters are 7 bit and can be replaced first */ |
62f7daa5 |
92 | |
098ea084 |
93 | $string = htmlspecialchars ($string); |
a2a7852b |
94 | |
5dd23dac |
95 | /* controls cpu and memory intensive decoding cycles */ |
f03f6ee7 |
96 | if (! isset($aggressive_decoding) || $aggressive_decoding=="" ) { |
97 | $aggressive_decoding=false; } |
5dd23dac |
98 | |
b142de74 |
99 | $decode=fixcharset($charset); |
100 | $decodefile=SM_PATH . 'functions/decode/' . $decode . '.php'; |
101 | if (file_exists($decodefile)) { |
03db90bc |
102 | include_once($decodefile); |
103 | $ret = call_user_func('charset_decode_'.$decode, $string); |
a2a7852b |
104 | } else { |
03db90bc |
105 | $ret = $string; |
a2a7852b |
106 | } |
107 | return( $ret ); |
108 | } |
03db90bc |
109 | |
d3bab52e |
110 | /** |
111 | * Converts html string to given charset |
112 | * @param string $string |
113 | * @param string $charset |
78be8403 |
114 | * @param boolean $htmlencode keep htmlspecialchars encoding |
62f7daa5 |
115 | * @param string |
d3bab52e |
116 | */ |
78be8403 |
117 | function charset_encode($string,$charset,$htmlencode=true) { |
d3bab52e |
118 | global $default_charset; |
119 | |
78be8403 |
120 | // Undo html special chars |
121 | if (! $htmlencode ) { |
33991968 |
122 | $string = str_replace(array('&','>','<','"'),array('&','>','<','"'),$string); |
78be8403 |
123 | } |
124 | |
d3bab52e |
125 | $encode=fixcharset($charset); |
126 | $encodefile=SM_PATH . 'functions/encode/' . $encode . '.php'; |
127 | if (file_exists($encodefile)) { |
33991968 |
128 | include_once($encodefile); |
129 | $ret = call_user_func('charset_encode_'.$encode, $string); |
d3bab52e |
130 | } else { |
33991968 |
131 | include_once(SM_PATH . 'functions/encode/us_ascii.php'); |
132 | $ret = charset_encode_us_ascii($string); |
d3bab52e |
133 | } |
134 | return( $ret ); |
135 | } |
136 | |
137 | /** |
138 | * Combined decoding and encoding functions |
139 | * |
140 | * If conversion is done to charset different that utf-8, unsupported symbols |
141 | * will be replaced with question marks. |
142 | * @param string $in_charset initial charset |
143 | * @param string $string string that has to be converted |
144 | * @param string $out_charset final charset |
78be8403 |
145 | * @param boolean $htmlencode keep htmlspecialchars encoding |
d3bab52e |
146 | * @return string converted string |
147 | */ |
78be8403 |
148 | function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) { |
33991968 |
149 | $string=charset_decode($in_charset,$string); |
150 | $string=charset_encode($string,$out_charset,$htmlencode); |
151 | return $string; |
d3bab52e |
152 | } |
153 | |
b142de74 |
154 | /** |
155 | * Makes charset name suitable for decoding cycles |
156 | * |
157 | * @param string $charset Name of charset |
158 | * @return string $charset Adjusted name of charset |
159 | */ |
160 | function fixcharset($charset) { |
161 | // minus removed from function names |
162 | $charset=str_replace('-','_',$charset); |
62f7daa5 |
163 | |
b142de74 |
164 | // windows-125x and cp125x charsets |
165 | $charset=str_replace('windows_','cp',$charset); |
a2a7852b |
166 | |
b142de74 |
167 | // ibm > cp |
168 | $charset=str_replace('ibm','cp',$charset); |
169 | |
170 | // iso-8859-8-i -> iso-8859-8 |
171 | // use same cycle until I'll find differences |
172 | $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset); |
173 | |
174 | return $charset; |
175 | } |
a2a7852b |
176 | |
51468260 |
177 | /** |
a2a7852b |
178 | * Set up the language to be output |
179 | * if $do_search is true, then scan the browser information |
180 | * for a possible language that we know |
51468260 |
181 | * |
62f7daa5 |
182 | * Function sets system locale environment (LC_ALL, LANG, LANGUAGE), |
51468260 |
183 | * gettext translation bindings and html header information. |
184 | * |
5679405c |
185 | * Function returns error codes, if there is some fatal error. |
62f7daa5 |
186 | * 0 = no error, |
187 | * 1 = mbstring support is not present, |
51468260 |
188 | * 2 = mbstring support is not present, user's translation reverted to en_US. |
189 | * |
190 | * @param string $sm_language translation used by user's interface |
191 | * @param bool $do_search use browser's preferred language detection functions. Defaults to false. |
192 | * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false. |
62f7daa5 |
193 | * @return int function execution error codes. |
a2a7852b |
194 | */ |
67a8c90a |
195 | function set_up_language($sm_language, $do_search = false, $default = false) { |
a2a7852b |
196 | |
197 | static $SetupAlready = 0; |
9eb0fbd4 |
198 | global $use_gettext, $languages, |
fe48c808 |
199 | $squirrelmail_language, $squirrelmail_default_language, $default_charset, |
51468260 |
200 | $sm_notAlias, $username, $data_dir; |
a2a7852b |
201 | |
202 | if ($SetupAlready) { |
203 | return; |
204 | } |
a65846a7 |
205 | |
5c920668 |
206 | $SetupAlready = TRUE; |
961ca3d8 |
207 | sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER); |
a2a7852b |
208 | |
961ca3d8 |
209 | if ($do_search && ! $sm_language && isset($accept_lang)) { |
210 | $sm_language = substr($accept_lang, 0, 2); |
a2a7852b |
211 | } |
62f7daa5 |
212 | |
67a8c90a |
213 | if ((!$sm_language||$default) && isset($squirrelmail_default_language)) { |
a2a7852b |
214 | $squirrelmail_language = $squirrelmail_default_language; |
66d7950f |
215 | $sm_language = $squirrelmail_default_language; |
a2a7852b |
216 | } |
217 | $sm_notAlias = $sm_language; |
62f7daa5 |
218 | |
3ec81e63 |
219 | // Catching removed translation |
220 | // System reverts to English translation if user prefs contain translation |
2ba706ef |
221 | // that is not available in $languages array |
3ec81e63 |
222 | if (!isset($languages[$sm_notAlias])) { |
223 | $sm_notAlias="en_US"; |
224 | } |
225 | |
a2a7852b |
226 | while (isset($languages[$sm_notAlias]['ALIAS'])) { |
227 | $sm_notAlias = $languages[$sm_notAlias]['ALIAS']; |
228 | } |
229 | |
88cb1b4d |
230 | if ( isset($sm_language) && |
5c920668 |
231 | $use_gettext && |
232 | $sm_language != '' && |
233 | isset($languages[$sm_notAlias]['CHARSET']) ) { |
a65846a7 |
234 | bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' ); |
88cb1b4d |
235 | textdomain( 'squirrelmail' ); |
03db90bc |
236 | if (function_exists('bind_textdomain_codeset')) { |
237 | if ($sm_notAlias == 'ja_JP') { |
238 | bind_textdomain_codeset ("squirrelmail", 'EUC-JP'); |
a5970d71 |
239 | } else { |
03db90bc |
240 | bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] ); |
241 | } |
242 | } |
243 | if (isset($languages[$sm_notAlias]['LOCALE'])){ |
244 | $longlocale=$languages[$sm_notAlias]['LOCALE']; |
245 | } else { |
246 | $longlocale=$sm_notAlias; |
247 | } |
88cb1b4d |
248 | if ( !ini_get('safe_mode') && |
f2374580 |
249 | getenv( 'LC_ALL' ) != $longlocale ) { |
250 | putenv( "LC_ALL=$longlocale" ); |
251 | putenv( "LANG=$longlocale" ); |
252 | putenv( "LANGUAGE=$longlocale" ); |
475df436 |
253 | if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" ); |
a2a7852b |
254 | } |
03db90bc |
255 | setlocale(LC_ALL, $longlocale); |
475df436 |
256 | if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE,'C'); |
03db90bc |
257 | |
258 | // Set text direction/alignment variables |
62f7daa5 |
259 | if (isset($languages[$sm_notAlias]['DIR']) && |
03db90bc |
260 | $languages[$sm_notAlias]['DIR'] == 'rtl') { |
261 | /** |
262 | * Text direction |
263 | * @global string $text_direction |
264 | */ |
265 | $text_direction='rtl'; |
266 | /** |
267 | * Left alignment |
268 | * @global string $left_align |
269 | */ |
270 | $left_align='right'; |
271 | /** |
272 | * Right alignment |
273 | * @global string $right_align |
274 | */ |
275 | $right_align='left'; |
276 | } else { |
277 | $text_direction='ltr'; |
278 | $left_align='left'; |
279 | $right_align='right'; |
280 | } |
281 | |
282 | $squirrelmail_language = $sm_notAlias; |
a5970d71 |
283 | if ($squirrelmail_language == 'ja_JP') { |
b05c8961 |
284 | header ('Content-Type: text/html; charset=EUC-JP'); |
285 | if (!function_exists('mb_internal_encoding')) { |
03db90bc |
286 | // Error messages can't be displayed here |
287 | $error = 1; |
288 | // Revert to English if possible. |
289 | if (function_exists('setPref') && $username!='' && $data_dir!="") { |
290 | setPref($data_dir, $username, 'language', "en_US"); |
291 | $error = 2; |
292 | } |
293 | // stop further execution in order not to get php errors on mb_internal_encoding(). |
294 | return $error; |
e842b215 |
295 | } |
296 | if (function_exists('mb_language')) { |
297 | mb_language('Japanese'); |
b05c8961 |
298 | } |
299 | mb_internal_encoding('EUC-JP'); |
300 | mb_http_output('pass'); |
fe48c808 |
301 | } elseif ($squirrelmail_language == 'en_US') { |
302 | header( 'Content-Type: text/html; charset=' . $default_charset ); |
b05c8961 |
303 | } else { |
fe48c808 |
304 | header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] ); |
305 | } |
a2a7852b |
306 | } |
51468260 |
307 | return 0; |
b05c8961 |
308 | } |
a2a7852b |
309 | |
51468260 |
310 | /** |
311 | * Sets default_charset variable according to the one that is used by user's translations. |
312 | * |
313 | * Function changes global $default_charset variable in order to be sure, that it |
314 | * contains charset used by user's translation. Sanity of $squirrelmail_default_language |
315 | * and $default_charset combination provided in SquirrelMail config is also tested. |
316 | * |
317 | * There can be a $default_charset setting in the |
318 | * config.php file, but the user may have a different language |
319 | * selected for a user interface. This function checks the |
320 | * language selected by the user and tags the outgoing messages |
321 | * with the appropriate charset corresponding to the language |
322 | * selection. This is "more right" (tm), than just stamping the |
323 | * message blindly with the system-wide $default_charset. |
324 | */ |
a2a7852b |
325 | function set_my_charset(){ |
94965562 |
326 | global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language; |
88cb1b4d |
327 | |
a2a7852b |
328 | $my_language = getPref($data_dir, $username, 'language'); |
5c920668 |
329 | if (!$my_language) { |
94965562 |
330 | $my_language = $squirrelmail_default_language ; |
5c920668 |
331 | } |
3ec81e63 |
332 | // Catch removed translation |
333 | if (!isset($languages[$my_language])) { |
334 | $my_language="en_US"; |
335 | } |
a2a7852b |
336 | while (isset($languages[$my_language]['ALIAS'])) { |
f7e8861e |
337 | $my_language = $languages[$my_language]['ALIAS']; |
a2a7852b |
338 | } |
5c920668 |
339 | $my_charset = $languages[$my_language]['CHARSET']; |
fe48c808 |
340 | if ($my_language!='en_US') { |
a2a7852b |
341 | $default_charset = $my_charset; |
342 | } |
343 | } |
344 | |
a2a7852b |
345 | /* ------------------------------ main --------------------------- */ |
346 | |
5c920668 |
347 | global $squirrelmail_language, $languages, $use_gettext; |
348 | |
a2a7852b |
349 | if (! isset($squirrelmail_language)) { |
350 | $squirrelmail_language = ''; |
351 | } |
352 | |
51468260 |
353 | /** |
354 | * Array specifies the available translations. |
355 | * |
356 | * Structure of array: |
357 | * $languages['language']['variable'] = 'value' |
62f7daa5 |
358 | * |
51468260 |
359 | * Possible 'variable' names: |
360 | * NAME - Translation name in English |
361 | * CHARSET - Encoding used by translation |
362 | * ALIAS - used when 'language' is only short name and 'value' should provide long language name |
363 | * ALTNAME - Native translation name. Any 8bit symbols must be html encoded. |
364 | * LOCALE - Full locale name (in xx_XX.charset format) |
365 | * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr' |
1bb86586 |
366 | * XTRA_CODE - translation uses special functions. See doc/i18n.txt |
62f7daa5 |
367 | * |
51468260 |
368 | * Each 'language' definition requires NAME+CHARSET or ALIAS variables. |
369 | * |
370 | * @name $languages |
a8a1c36d |
371 | * @global array $languages |
51468260 |
372 | */ |
a8fa8e33 |
373 | $languages['bg_BG']['NAME'] = 'Bulgarian'; |
374 | $languages['bg_BG']['ALTNAME'] = 'Български'; |
375 | $languages['bg_BG']['CHARSET'] = 'windows-1251'; |
c30be3cf |
376 | $languages['bg_BG']['LOCALE'] = 'bg_BG.CP1251'; |
a8fa8e33 |
377 | $languages['bg']['ALIAS'] = 'bg_BG'; |
378 | |
57564e64 |
379 | $languages['bn_IN']['NAME'] = 'Bengali'; |
380 | $languages['bn_IN']['CHARSET'] = 'utf-8'; |
381 | $languages['bn_IN']['LOCALE'] = 'bn_IN.UTF-8'; |
382 | $languages['bn']['ALIAS'] = 'bn_IN'; |
383 | |
a8fa8e33 |
384 | $languages['ca_ES']['NAME'] = 'Catalan'; |
385 | $languages['ca_ES']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
386 | $languages['ca_ES']['LOCALE'] = 'ca_ES.ISO8859-1'; |
a8fa8e33 |
387 | $languages['ca']['ALIAS'] = 'ca_ES'; |
388 | |
389 | $languages['cs_CZ']['NAME'] = 'Czech'; |
390 | $languages['cs_CZ']['ALTNAME'] = 'Čeština'; |
391 | $languages['cs_CZ']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
392 | $languages['cs_CZ']['LOCALE'] = 'cs_CZ.ISO8859-2'; |
a8fa8e33 |
393 | $languages['cs']['ALIAS'] = 'cs_CZ'; |
394 | |
395 | $languages['cy_GB']['NAME'] = 'Welsh'; |
396 | $languages['cy_GB']['ALTNAME'] = 'Cymraeg'; |
397 | $languages['cy_GB']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
398 | $languages['cy_GB']['LOCALE'] = 'cy_GB.ISO8859-1'; |
a8fa8e33 |
399 | $languages['cy']['ALIAS'] = 'cy_GB'; |
400 | |
401 | // Danish locale is da_DK. |
402 | $languages['da_DK']['NAME'] = 'Danish'; |
403 | $languages['da_DK']['ALTNAME'] = 'Dansk'; |
404 | $languages['da_DK']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
405 | $languages['da_DK']['LOCALE'] = 'da_DK.ISO8859-1'; |
a8fa8e33 |
406 | $languages['da']['ALIAS'] = 'da_DK'; |
407 | |
408 | $languages['de_DE']['NAME'] = 'German'; |
409 | $languages['de_DE']['ALTNAME'] = 'Deutsch'; |
410 | $languages['de_DE']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
411 | $languages['de_DE']['LOCALE'] = 'de_DE.ISO8859-1'; |
a8fa8e33 |
412 | $languages['de']['ALIAS'] = 'de_DE'; |
413 | |
414 | $languages['el_GR']['NAME'] = 'Greek'; |
415 | $languages['el_GR']['ALTNAME'] = 'Ελληνικά'; |
416 | $languages['el_GR']['CHARSET'] = 'iso-8859-7'; |
a00d341d |
417 | $languages['el_GR']['LOCALE'] = 'el_GR.ISO8859-7'; |
a8fa8e33 |
418 | $languages['el']['ALIAS'] = 'el_GR'; |
a2a7852b |
419 | |
3bb3d83b |
420 | $languages['en_GB']['NAME'] = 'British'; |
421 | $languages['en_GB']['CHARSET'] = 'iso-8859-15'; |
a00d341d |
422 | $languages['en_GB']['LOCALE'] = 'en_GB.ISO8859-15'; |
3bb3d83b |
423 | |
5c920668 |
424 | $languages['en_US']['NAME'] = 'English'; |
425 | $languages['en_US']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
426 | $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1'; |
5c920668 |
427 | $languages['en']['ALIAS'] = 'en_US'; |
a2a7852b |
428 | |
a8fa8e33 |
429 | $languages['es_ES']['NAME'] = 'Spanish'; |
430 | $languages['es_ES']['ALTNAME'] = 'Español'; |
431 | $languages['es_ES']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
432 | $languages['es_ES']['LOCALE'] = 'es_ES.ISO8859-1'; |
a8fa8e33 |
433 | $languages['es']['ALIAS'] = 'es_ES'; |
434 | |
435 | $languages['et_EE']['NAME'] = 'Estonian'; |
436 | $languages['et_EE']['CHARSET'] = 'iso-8859-15'; |
a00d341d |
437 | $languages['et_EE']['LOCALE'] = 'et_EE.ISO8859-15'; |
a8fa8e33 |
438 | $languages['et']['ALIAS'] = 'et_EE'; |
439 | |
2d268514 |
440 | $languages['eu_ES']['NAME'] = 'Basque'; |
441 | $languages['eu_ES']['CHARSET'] = 'iso-8859-1'; |
442 | $languages['eu_ES']['LOCALE'] = 'eu_ES.ISO8859-1'; |
443 | $languages['eu']['ALIAS'] = 'eu_ES'; |
444 | |
a8fa8e33 |
445 | $languages['fo_FO']['NAME'] = 'Faroese'; |
446 | $languages['fo_FO']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
447 | $languages['fo_FO']['LOCALE'] = 'fo_FO.ISO8859-1'; |
a8fa8e33 |
448 | $languages['fo']['ALIAS'] = 'fo_FO'; |
449 | |
450 | $languages['fi_FI']['NAME'] = 'Finnish'; |
451 | $languages['fi_FI']['ALTNAME'] = 'Suomi'; |
452 | $languages['fi_FI']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
453 | $languages['fi_FI']['LOCALE'] = 'fi_FI.ISO8859-1'; |
a8fa8e33 |
454 | $languages['fi']['ALIAS'] = 'fi_FI'; |
455 | |
456 | $languages['fr_FR']['NAME'] = 'French'; |
457 | $languages['fr_FR']['ALTNAME'] = 'Français'; |
458 | $languages['fr_FR']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
459 | $languages['fr_FR']['LOCALE'] = 'fr_FR.ISO8859-1'; |
a8fa8e33 |
460 | $languages['fr']['ALIAS'] = 'fr_FR'; |
461 | |
462 | $languages['hr_HR']['NAME'] = 'Croatian'; |
463 | $languages['hr_HR']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
464 | $languages['hr_HR']['LOCALE'] = 'hr_HR.ISO8859-2'; |
a8fa8e33 |
465 | $languages['hr']['ALIAS'] = 'hr_HR'; |
466 | |
467 | $languages['hu_HU']['NAME'] = 'Hungarian'; |
468 | $languages['hu_HU']['ALTNAME'] = 'Magyar'; |
469 | $languages['hu_HU']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
470 | $languages['hu_HU']['LOCALE'] = 'hu_HU.ISO8859-2'; |
a8fa8e33 |
471 | $languages['hu']['ALIAS'] = 'hu_HU'; |
472 | |
473 | $languages['id_ID']['NAME'] = 'Indonesian'; |
474 | $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia'; |
475 | $languages['id_ID']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
476 | $languages['id_ID']['LOCALE'] = 'id_ID.ISO8859-1'; |
a8fa8e33 |
477 | $languages['id']['ALIAS'] = 'id_ID'; |
478 | |
479 | $languages['is_IS']['NAME'] = 'Icelandic'; |
480 | $languages['is_IS']['ALTNAME'] = 'Íslenska'; |
481 | $languages['is_IS']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
482 | $languages['is_IS']['LOCALE'] = 'is_IS.ISO8859-1'; |
a8fa8e33 |
483 | $languages['is']['ALIAS'] = 'is_IS'; |
484 | |
485 | $languages['it_IT']['NAME'] = 'Italian'; |
486 | $languages['it_IT']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
487 | $languages['it_IT']['LOCALE'] = 'it_IT.ISO8859-1'; |
a8fa8e33 |
488 | $languages['it']['ALIAS'] = 'it_IT'; |
489 | |
490 | $languages['ja_JP']['NAME'] = 'Japanese'; |
491 | $languages['ja_JP']['ALTNAME'] = '日本語'; |
492 | $languages['ja_JP']['CHARSET'] = 'iso-2022-jp'; |
51468260 |
493 | $languages['ja_JP']['LOCALE'] = 'ja_JP.EUC-JP'; |
1bb86586 |
494 | $languages['ja_JP']['XTRA_CODE'] = 'japanese_xtra'; |
a8fa8e33 |
495 | $languages['ja']['ALIAS'] = 'ja_JP'; |
496 | |
497 | $languages['ko_KR']['NAME'] = 'Korean'; |
498 | $languages['ko_KR']['CHARSET'] = 'euc-KR'; |
c30be3cf |
499 | $languages['ko_KR']['LOCALE'] = 'ko_KR.EUC-KR'; |
1bb86586 |
500 | $languages['ko_KR']['XTRA_CODE'] = 'korean_xtra'; |
a8fa8e33 |
501 | $languages['ko']['ALIAS'] = 'ko_KR'; |
502 | |
503 | $languages['lt_LT']['NAME'] = 'Lithuanian'; |
504 | $languages['lt_LT']['ALTNAME'] = 'Lietuvių'; |
505 | $languages['lt_LT']['CHARSET'] = 'utf-8'; |
506 | $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8'; |
507 | $languages['lt']['ALIAS'] = 'lt_LT'; |
508 | |
509 | $languages['nl_NL']['NAME'] = 'Dutch'; |
510 | $languages['nl_NL']['ALTNAME'] = 'Nederlands'; |
511 | $languages['nl_NL']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
512 | $languages['nl_NL']['LOCALE'] = 'nl_NL.ISO8859-1'; |
a8fa8e33 |
513 | $languages['nl']['ALIAS'] = 'nl_NL'; |
514 | |
515 | $languages['ms_MY']['NAME'] = 'Malay'; |
516 | $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu'; |
517 | $languages['ms_MY']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
518 | $languages['ms_MY']['LOCALE'] = 'ms_MY.ISO8859-1'; |
a8fa8e33 |
519 | $languages['my']['ALIAS'] = 'ms_MY'; |
520 | |
850db3c8 |
521 | $languages['nb_NO']['NAME'] = 'Norwegian (Bokmål)'; |
522 | $languages['nb_NO']['ALTNAME'] = 'Norsk (Bokmål)'; |
523 | $languages['nb_NO']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
524 | $languages['nb_NO']['LOCALE'] = 'nb_NO.ISO8859-1'; |
850db3c8 |
525 | $languages['nb']['ALIAS'] = 'nb_NO'; |
a8fa8e33 |
526 | |
527 | $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)'; |
528 | $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)'; |
529 | $languages['nn_NO']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
530 | $languages['nn_NO']['LOCALE'] = 'nn_NO.ISO8859-1'; |
a8fa8e33 |
531 | |
532 | $languages['pl_PL']['NAME'] = 'Polish'; |
533 | $languages['pl_PL']['ALTNAME'] = 'Polski'; |
534 | $languages['pl_PL']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
535 | $languages['pl_PL']['LOCALE'] = 'pl_PL.ISO8859-2'; |
a8fa8e33 |
536 | $languages['pl']['ALIAS'] = 'pl_PL'; |
537 | |
538 | $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)'; |
539 | $languages['pt_PT']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
540 | $languages['pt_PT']['LOCALE'] = 'pt_PT.ISO8859-1'; |
a8fa8e33 |
541 | $languages['pt']['ALIAS'] = 'pt_PT'; |
542 | |
543 | $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)'; |
544 | $languages['pt_BR']['ALTNAME'] = 'Português do Brasil'; |
545 | $languages['pt_BR']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
546 | $languages['pt_BR']['LOCALE'] = 'pt_BR.ISO8859-1'; |
a8fa8e33 |
547 | |
548 | $languages['ro_RO']['NAME'] = 'Romanian'; |
549 | $languages['ro_RO']['ALTNAME'] = 'Română'; |
550 | $languages['ro_RO']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
551 | $languages['ro_RO']['LOCALE'] = 'ro_RO.ISO8859-2'; |
a8fa8e33 |
552 | $languages['ro']['ALIAS'] = 'ro_RO'; |
553 | |
554 | $languages['ru_RU']['NAME'] = 'Russian'; |
555 | $languages['ru_RU']['ALTNAME'] = 'Русский'; |
556 | $languages['ru_RU']['CHARSET'] = 'utf-8'; |
c30be3cf |
557 | $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8'; |
a8fa8e33 |
558 | $languages['ru']['ALIAS'] = 'ru_RU'; |
559 | |
c30be3cf |
560 | $languages['sk_SK']['NAME'] = 'Slovak'; |
561 | $languages['sk_SK']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
562 | $languages['sk_SK']['LOCALE'] = 'sk_SK.ISO8859-2'; |
c30be3cf |
563 | $languages['sk']['ALIAS'] = 'sk_SK'; |
a8fa8e33 |
564 | |
565 | $languages['sl_SI']['NAME'] = 'Slovenian'; |
566 | $languages['sl_SI']['ALTNAME'] = 'Slovenščina'; |
567 | $languages['sl_SI']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
568 | $languages['sl_SI']['LOCALE'] = 'sl_SI.ISO8859-2'; |
a8fa8e33 |
569 | $languages['sl']['ALIAS'] = 'sl_SI'; |
570 | |
571 | $languages['sr_YU']['NAME'] = 'Serbian'; |
572 | $languages['sr_YU']['ALTNAME'] = 'Srpski'; |
573 | $languages['sr_YU']['CHARSET'] = 'iso-8859-2'; |
a00d341d |
574 | $languages['sr_YU']['LOCALE'] = 'sr_YU.ISO8859-2'; |
a8fa8e33 |
575 | $languages['sr']['ALIAS'] = 'sr_YU'; |
576 | |
577 | $languages['sv_SE']['NAME'] = 'Swedish'; |
578 | $languages['sv_SE']['ALTNAME'] = 'Svenska'; |
579 | $languages['sv_SE']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
580 | $languages['sv_SE']['LOCALE'] = 'sv_SE.ISO8859-1'; |
a8fa8e33 |
581 | $languages['sv']['ALIAS'] = 'sv_SE'; |
582 | |
583 | $languages['th_TH']['NAME'] = 'Thai'; |
584 | $languages['th_TH']['CHARSET'] = 'tis-620'; |
c30be3cf |
585 | $languages['th_TH']['LOCALE'] = 'th_TH.TIS-620'; |
a8fa8e33 |
586 | $languages['th']['ALIAS'] = 'th_TH'; |
587 | |
551a09c7 |
588 | $languages['tl_PH']['NAME'] = 'Tagalog'; |
589 | $languages['tl_PH']['CHARSET'] = 'iso-8859-1'; |
a00d341d |
590 | $languages['tl_PH']['LOCALE'] = 'tl_PH.ISO8859-1'; |
551a09c7 |
591 | $languages['tl']['ALIAS'] = 'tl_PH'; |
592 | |
a8fa8e33 |
593 | $languages['tr_TR']['NAME'] = 'Turkish'; |
594 | $languages['tr_TR']['CHARSET'] = 'iso-8859-9'; |
a00d341d |
595 | $languages['tr_TR']['LOCALE'] = 'tr_TR.ISO8859-9'; |
a8fa8e33 |
596 | $languages['tr']['ALIAS'] = 'tr_TR'; |
597 | |
598 | $languages['zh_TW']['NAME'] = 'Chinese Trad'; |
599 | $languages['zh_TW']['CHARSET'] = 'big5'; |
c30be3cf |
600 | $languages['zh_TW']['LOCALE'] = 'zh_TW.BIG5'; |
a8fa8e33 |
601 | $languages['tw']['ALIAS'] = 'zh_TW'; |
602 | |
603 | $languages['zh_CN']['NAME'] = 'Chinese Simp'; |
604 | $languages['zh_CN']['CHARSET'] = 'gb2312'; |
c30be3cf |
605 | $languages['zh_CN']['LOCALE'] = 'zh_CN.GB2312'; |
a8fa8e33 |
606 | $languages['cn']['ALIAS'] = 'zh_CN'; |
060c9483 |
607 | |
a8fa8e33 |
608 | $languages['uk_UA']['NAME'] = 'Ukrainian'; |
609 | $languages['uk_UA']['CHARSET'] = 'koi8-u'; |
c30be3cf |
610 | $languages['uk_UA']['LOCALE'] = 'uk_UA.KOI8-U'; |
a8fa8e33 |
611 | $languages['uk']['ALIAS'] = 'uk_UA'; |
c30be3cf |
612 | |
613 | $languages['ru_UA']['NAME'] = 'Russian (Ukrainian)'; |
614 | $languages['ru_UA']['CHARSET'] = 'koi8-r'; |
615 | $languages['ru_UA']['LOCALE'] = 'ru_UA.KOI8-R'; |
616 | |
87c6b544 |
617 | /* |
850db3c8 |
618 | $languages['vi_VN']['NAME'] = 'Vietnamese'; |
619 | $languages['vi_VN']['CHARSET'] = 'utf-8'; |
620 | $languages['vi']['ALIAS'] = 'vi_VN'; |
87c6b544 |
621 | */ |
a8fa8e33 |
622 | |
d3b57948 |
623 | // Right to left languages |
a8fa8e33 |
624 | $languages['ar']['NAME'] = 'Arabic'; |
625 | $languages['ar']['CHARSET'] = 'windows-1256'; |
626 | $languages['ar']['DIR'] = 'rtl'; |
627 | |
4417eead |
628 | $languages['fa_IR']['NAME'] = 'Farsi'; |
629 | $languages['fa_IR']['CHARSET'] = 'utf-8'; |
630 | $languages['fa_IR']['DIR'] = 'rtl'; |
631 | $languages['fa_IR']['LOCALE'] = 'fa_IR.UTF-8'; |
632 | $languages['fa']['ALIAS'] = 'fa_IR'; |
633 | |
a8fa8e33 |
634 | $languages['he_IL']['NAME'] = 'Hebrew'; |
635 | $languages['he_IL']['CHARSET'] = 'windows-1255'; |
c30be3cf |
636 | $languages['he_IL']['LOCALE'] = 'he_IL.CP1255'; |
a8fa8e33 |
637 | $languages['he_IL']['DIR'] = 'rtl'; |
638 | $languages['he']['ALIAS'] = 'he_IL'; |
d3b57948 |
639 | |
2ba590f9 |
640 | $languages['ug']['NAME'] = 'Uighur'; |
641 | $languages['ug']['CHARSET'] = 'utf-8'; |
642 | $languages['ug']['DIR'] = 'rtl'; |
643 | |
5c920668 |
644 | /* Detect whether gettext is installed. */ |
a2a7852b |
645 | $gettext_flags = 0; |
646 | if (function_exists('_')) { |
647 | $gettext_flags += 1; |
648 | } |
649 | if (function_exists('bindtextdomain')) { |
650 | $gettext_flags += 2; |
651 | } |
652 | if (function_exists('textdomain')) { |
653 | $gettext_flags += 4; |
654 | } |
655 | |
5c920668 |
656 | /* If gettext is fully loaded, cool */ |
a2a7852b |
657 | if ($gettext_flags == 7) { |
658 | $use_gettext = true; |
659 | } |
5c920668 |
660 | /* If we can fake gettext, try that */ |
a2a7852b |
661 | elseif ($gettext_flags == 0) { |
662 | $use_gettext = true; |
e7ab8c9d |
663 | include_once(SM_PATH . 'functions/gettext.php'); |
a2a7852b |
664 | } else { |
5c920668 |
665 | /* Uh-ho. A weird install */ |
a2a7852b |
666 | if (! $gettext_flags & 1) { |
03db90bc |
667 | /** |
668 | * Function is used as replacement in broken installs |
669 | * @ignore |
670 | */ |
a2a7852b |
671 | function _($str) { |
672 | return $str; |
673 | } |
674 | } |
675 | if (! $gettext_flags & 2) { |
03db90bc |
676 | /** |
677 | * Function is used as replacement in broken installs |
678 | * @ignore |
679 | */ |
a2a7852b |
680 | function bindtextdomain() { |
681 | return; |
682 | } |
683 | } |
684 | if (! $gettext_flags & 4) { |
03db90bc |
685 | /** |
686 | * Function is used as replacemet in broken installs |
687 | * @ignore |
688 | */ |
a2a7852b |
689 | function textdomain() { |
690 | return; |
691 | } |
692 | } |
693 | } |
694 | |
1d33e35e |
695 | |
51468260 |
696 | /** |
1d33e35e |
697 | * Japanese charset extra function |
698 | * |
51468260 |
699 | * Action performed by function is defined by first argument. |
700 | * Default return value is defined by second argument. |
701 | * Use of third argument depends on action. |
702 | * |
a8a1c36d |
703 | * @param string $action action performed by this function. |
51468260 |
704 | * possible values: |
03db90bc |
705 | * decode - convert returned string to euc-jp. third argument unused |
706 | * encode - convert returned string to jis. third argument unused |
707 | * strimwidth - third argument=$width. trims string to $width symbols. |
708 | * encodeheader - create base64 encoded header in iso-2022-jp. third argument unused |
709 | * decodeheader - return human readable string from mime header. string is returned in euc-jp. third argument unused |
710 | * downloadfilename - third argument $useragent. Arguments provide browser info. Returns shift-jis or euc-jp encoded file name |
711 | * wordwrap - third argument=$wrap. wraps text at $wrap symbols |
712 | * utf7-imap_encode - returns string converted from euc-jp to utf7-imap. third argument unused |
713 | * utf7-imap_decode - returns string converted from utf7-imap to euc-jp. third argument unused |
a8a1c36d |
714 | * @param string $ret default return value |
1d33e35e |
715 | */ |
1bb86586 |
716 | function japanese_xtra() { |
1d33e35e |
717 | $ret = func_get_arg(1); /* default return value */ |
718 | if (function_exists('mb_detect_encoding')) { |
719 | switch (func_get_arg(0)) { /* action */ |
720 | case 'decode': |
e842b215 |
721 | $detect_encoding = @mb_detect_encoding($ret); |
1d33e35e |
722 | if ($detect_encoding == 'JIS' || |
723 | $detect_encoding == 'EUC-JP' || |
e842b215 |
724 | $detect_encoding == 'SJIS' || |
725 | $detect_encoding == 'UTF-8') { |
62f7daa5 |
726 | |
e842b215 |
727 | $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV"); |
1d33e35e |
728 | } |
729 | break; |
730 | case 'encode': |
e842b215 |
731 | $detect_encoding = @mb_detect_encoding($ret); |
1d33e35e |
732 | if ($detect_encoding == 'JIS' || |
733 | $detect_encoding == 'EUC-JP' || |
e842b215 |
734 | $detect_encoding == 'SJIS' || |
735 | $detect_encoding == 'UTF-8') { |
62f7daa5 |
736 | |
e842b215 |
737 | $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO'); |
1d33e35e |
738 | } |
739 | break; |
740 | case 'strimwidth': |
741 | $width = func_get_arg(2); |
62f7daa5 |
742 | $ret = mb_strimwidth($ret, 0, $width, '...'); |
1d33e35e |
743 | break; |
744 | case 'encodeheader': |
8ba05cbe |
745 | $result = ''; |
746 | if (strlen($ret) > 0) { |
747 | $tmpstr = mb_substr($ret, 0, 1); |
748 | $prevcsize = strlen($tmpstr); |
749 | for ($i = 1; $i < mb_strlen($ret); $i++) { |
750 | $tmp = mb_substr($ret, $i, 1); |
751 | if (strlen($tmp) == $prevcsize) { |
752 | $tmpstr .= $tmp; |
753 | } else { |
754 | if ($prevcsize == 1) { |
755 | $result .= $tmpstr; |
756 | } else { |
62f7daa5 |
757 | $result .= str_replace(' ', '', |
e842b215 |
758 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
8ba05cbe |
759 | } |
760 | $tmpstr = $tmp; |
761 | $prevcsize = strlen($tmp); |
762 | } |
763 | } |
764 | if (strlen($tmpstr)) { |
765 | if (strlen(mb_substr($tmpstr, 0, 1)) == 1) |
766 | $result .= $tmpstr; |
767 | else |
e842b215 |
768 | $result .= str_replace(' ', '', |
769 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
8ba05cbe |
770 | } |
771 | } |
772 | $ret = $result; |
1d33e35e |
773 | break; |
774 | case 'decodeheader': |
775 | $ret = str_replace("\t", "", $ret); |
776 | if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret)) |
e842b215 |
777 | $ret = @mb_decode_mimeheader($ret); |
778 | $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
1d33e35e |
779 | break; |
780 | case 'downloadfilename': |
781 | $useragent = func_get_arg(2); |
782 | if (strstr($useragent, 'Windows') !== false || |
783 | strstr($useragent, 'Mac_') !== false) { |
784 | $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO'); |
785 | } else { |
786 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
787 | } |
788 | break; |
e842b215 |
789 | case 'wordwrap': |
790 | $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" . |
791 | "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" . |
792 | "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" . |
793 | "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" . |
794 | "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" . |
795 | "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" . |
796 | "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" . |
797 | "\xa8\xa1\xa9\xa1\xcf\xa1\xd1"; |
798 | $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" . |
799 | "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef"; |
800 | $wrap = func_get_arg(2); |
62f7daa5 |
801 | |
802 | if (strlen($ret) >= $wrap && |
e842b215 |
803 | substr($ret, 0, 1) != '>' && |
804 | strpos($ret, 'http://') === FALSE && |
805 | strpos($ret, 'https://') === FALSE && |
806 | strpos($ret, 'ftp://') === FALSE) { |
62f7daa5 |
807 | |
e842b215 |
808 | $ret = mb_convert_kana($ret, "KV"); |
809 | |
810 | $line_new = ''; |
811 | $ptr = 0; |
62f7daa5 |
812 | |
e842b215 |
813 | while ($ptr < strlen($ret) - 1) { |
814 | $l = mb_strcut($ret, $ptr, $wrap); |
815 | $ptr += strlen($l); |
816 | $tmp = $l; |
62f7daa5 |
817 | |
e842b215 |
818 | $l = mb_strcut($ret, $ptr, 2); |
819 | while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) { |
820 | $tmp .= $l; |
821 | $ptr += strlen($l); |
822 | $l = mb_strcut($ret, $ptr, 1); |
823 | } |
824 | $line_new .= $tmp; |
825 | if ($ptr < strlen($ret) - 1) |
826 | $line_new .= "\n"; |
827 | } |
828 | $ret = $line_new; |
829 | } |
830 | break; |
831 | case 'utf7-imap_encode': |
832 | $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP'); |
833 | break; |
834 | case 'utf7-imap_decode': |
835 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP'); |
836 | break; |
1d33e35e |
837 | } |
838 | } |
839 | return $ret; |
840 | } |
841 | |
1bb86586 |
842 | /************************** |
843 | * Japanese extra functions |
844 | **************************/ |
1d33e35e |
845 | |
51468260 |
846 | /** |
1bb86586 |
847 | * Japanese decoding function |
80b0091e |
848 | * |
62f7daa5 |
849 | * converts string to euc-jp, if string uses JIS, EUC-JP, ShiftJIS or UTF-8 |
80b0091e |
850 | * charset. Needs mbstring support in php. |
851 | * @param string $ret text, that has to be converted |
852 | * @return string converted string |
1bb86586 |
853 | * @since 1.5.1 |
854 | */ |
855 | function japanese_xtra_decode($ret) { |
856 | if (function_exists('mb_detect_encoding')) { |
857 | $detect_encoding = @mb_detect_encoding($ret); |
858 | if ($detect_encoding == 'JIS' || |
859 | $detect_encoding == 'EUC-JP' || |
860 | $detect_encoding == 'SJIS' || |
861 | $detect_encoding == 'UTF-8') { |
862 | |
863 | $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV"); |
864 | } |
865 | } |
866 | return $ret; |
867 | } |
868 | |
869 | /** |
870 | * Japanese encoding function |
80b0091e |
871 | * |
872 | * converts string to jis, if string uses JIS, EUC-JP, ShiftJIS or UTF-8 |
873 | * charset. Needs mbstring support in php. |
874 | * @param string $ret text, that has to be converted |
875 | * @return string converted text |
1bb86586 |
876 | * @since 1.5.1 |
877 | */ |
878 | function japanese_xtra_encode($ret) { |
879 | if (function_exists('mb_detect_encoding')) { |
880 | $detect_encoding = @mb_detect_encoding($ret); |
881 | if ($detect_encoding == 'JIS' || |
882 | $detect_encoding == 'EUC-JP' || |
883 | $detect_encoding == 'SJIS' || |
884 | $detect_encoding == 'UTF-8') { |
62f7daa5 |
885 | |
1bb86586 |
886 | $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO'); |
887 | } |
888 | } |
889 | return $ret; |
890 | } |
891 | |
892 | /** |
893 | * Japanese header encoding function |
80b0091e |
894 | * |
895 | * creates base64 encoded header in iso-2022-jp charset |
896 | * @param string $ret text, that has to be converted |
897 | * @return string mime base64 encoded string |
1bb86586 |
898 | * @since 1.5.1 |
899 | */ |
900 | function japanese_xtra_encodeheader($ret) { |
901 | if (function_exists('mb_detect_encoding')) { |
902 | $result = ''; |
903 | if (strlen($ret) > 0) { |
904 | $tmpstr = mb_substr($ret, 0, 1); |
905 | $prevcsize = strlen($tmpstr); |
906 | for ($i = 1; $i < mb_strlen($ret); $i++) { |
907 | $tmp = mb_substr($ret, $i, 1); |
908 | if (strlen($tmp) == $prevcsize) { |
909 | $tmpstr .= $tmp; |
910 | } else { |
911 | if ($prevcsize == 1) { |
912 | $result .= $tmpstr; |
913 | } else { |
62f7daa5 |
914 | $result .= str_replace(' ', '', |
1bb86586 |
915 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
916 | } |
917 | $tmpstr = $tmp; |
918 | $prevcsize = strlen($tmp); |
919 | } |
920 | } |
921 | if (strlen($tmpstr)) { |
922 | if (strlen(mb_substr($tmpstr, 0, 1)) == 1) |
923 | $result .= $tmpstr; |
924 | else |
925 | $result .= str_replace(' ', '', |
926 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
927 | } |
928 | } |
929 | $ret = $result; |
930 | } |
931 | return $ret; |
932 | } |
933 | |
934 | /** |
935 | * Japanese header decoding function |
80b0091e |
936 | * |
62f7daa5 |
937 | * return human readable string from mime header. string is returned in euc-jp |
80b0091e |
938 | * charset. |
939 | * @param string $ret header string |
940 | * @return string decoded header string |
1bb86586 |
941 | * @since 1.5.1 |
942 | */ |
943 | function japanese_xtra_decodeheader($ret) { |
944 | if (function_exists('mb_detect_encoding')) { |
945 | $ret = str_replace("\t", "", $ret); |
946 | if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret)) |
947 | $ret = @mb_decode_mimeheader($ret); |
948 | $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
949 | } |
950 | return $ret; |
951 | } |
952 | |
953 | /** |
954 | * Japanese downloaded filename processing function |
80b0091e |
955 | * |
956 | * Returns shift-jis or euc-jp encoded file name |
957 | * @param string $ret string |
958 | * @param string $useragent browser |
959 | * @return string converted string |
1bb86586 |
960 | * @since 1.5.1 |
961 | */ |
962 | function japanese_xtra_downloadfilename($ret,$useragent) { |
963 | if (function_exists('mb_detect_encoding')) { |
964 | if (strstr($useragent, 'Windows') !== false || |
965 | strstr($useragent, 'Mac_') !== false) { |
966 | $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO'); |
967 | } else { |
968 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
969 | } |
970 | } |
971 | return $ret; |
972 | } |
973 | |
974 | /** |
975 | * Japanese wordwrap function |
62f7daa5 |
976 | * |
80b0091e |
977 | * wraps text at set number of symbols |
978 | * @param string $ret text |
979 | * @param integer $wrap number of symbols per line |
980 | * @return string wrapped text |
1bb86586 |
981 | * @since 1.5.1 |
982 | */ |
983 | function japanese_xtra_wordwrap($ret,$wrap) { |
984 | if (function_exists('mb_detect_encoding')) { |
985 | $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" . |
986 | "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" . |
987 | "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" . |
988 | "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" . |
989 | "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" . |
990 | "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" . |
991 | "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" . |
992 | "\xa8\xa1\xa9\xa1\xcf\xa1\xd1"; |
993 | $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" . |
994 | "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef"; |
62f7daa5 |
995 | |
996 | if (strlen($ret) >= $wrap && |
1bb86586 |
997 | substr($ret, 0, 1) != '>' && |
998 | strpos($ret, 'http://') === FALSE && |
999 | strpos($ret, 'https://') === FALSE && |
1000 | strpos($ret, 'ftp://') === FALSE) { |
1001 | |
1002 | $ret = mb_convert_kana($ret, "KV"); |
62f7daa5 |
1003 | |
1bb86586 |
1004 | $line_new = ''; |
1005 | $ptr = 0; |
62f7daa5 |
1006 | |
1bb86586 |
1007 | while ($ptr < strlen($ret) - 1) { |
1008 | $l = mb_strcut($ret, $ptr, $wrap); |
1009 | $ptr += strlen($l); |
1010 | $tmp = $l; |
62f7daa5 |
1011 | |
1bb86586 |
1012 | $l = mb_strcut($ret, $ptr, 2); |
1013 | while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) { |
1014 | $tmp .= $l; |
1015 | $ptr += strlen($l); |
1016 | $l = mb_strcut($ret, $ptr, 1); |
1017 | } |
1018 | $line_new .= $tmp; |
1019 | if ($ptr < strlen($ret) - 1) |
1020 | $line_new .= "\n"; |
1021 | } |
1022 | $ret = $line_new; |
1023 | } |
1024 | } |
1025 | return $ret; |
1026 | } |
1027 | |
1028 | /** |
1029 | * Japanese imap folder name encoding function |
80b0091e |
1030 | * |
1031 | * converts folder name from euc-jp to utf7-imap |
1032 | * @param string $ret folder name |
1033 | * @return string converted folder name |
1bb86586 |
1034 | * @since 1.5.1 |
1035 | */ |
1036 | function japanese_xtra_utf7_imap_encode($ret){ |
1037 | if (function_exists('mb_detect_encoding')) { |
1038 | $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP'); |
1039 | } |
1040 | return $ret; |
1041 | } |
1042 | |
1043 | /** |
1044 | * Japanese imap folder name decoding function |
80b0091e |
1045 | * |
1046 | * converts folder name from utf7-imap to euc-jp. |
1047 | * @param string $ret folder name in utf7-imap |
1048 | * @return string converted folder name |
1bb86586 |
1049 | * @since 1.5.1 |
1050 | */ |
1051 | function japanese_xtra_utf7_imap_decode($ret) { |
1052 | if (function_exists('mb_detect_encoding')) { |
1053 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP'); |
1054 | } |
1055 | return $ret; |
1056 | } |
1057 | |
1058 | /** |
1059 | * Japanese string trimming function |
80b0091e |
1060 | * |
1061 | * trims string to defined number of symbols |
1062 | * @param string $ret string |
1063 | * @param integer $width number of symbols |
1064 | * @return string trimmed string |
1bb86586 |
1065 | * @since 1.5.1 |
1066 | */ |
1067 | function japanese_xtra_strimwidth($ret,$width) { |
1068 | if (function_exists('mb_detect_encoding')) { |
1069 | $ret = mb_strimwidth($ret, 0, $width, '...'); |
1070 | } |
1071 | return $ret; |
1072 | } |
1073 | |
1074 | /******************************** |
51468260 |
1075 | * Korean charset extra functions |
1bb86586 |
1076 | ********************************/ |
1077 | |
1078 | /** |
1079 | * Korean downloaded filename processing functions |
51468260 |
1080 | * |
51468260 |
1081 | * @param string default return value |
62f7daa5 |
1082 | * @return string |
1d33e35e |
1083 | */ |
1bb86586 |
1084 | function korean_xtra_downloadfilename($ret) { |
1085 | $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */ |
1086 | for ($i=0;$i<strlen($ret);$i++) { |
1087 | if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */ |
1088 | $i++; |
1089 | continue; |
1090 | } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */ |
1091 | ($ret[$i] >= 'A' && $ret[$i] <= 'Z') || |
1092 | ($ret[$i] == '.') || ($ret[$i] == '-')) { |
1093 | continue; |
1094 | } else { |
1095 | $ret[$i] = '_'; |
1d33e35e |
1096 | } |
1d33e35e |
1097 | } |
1d33e35e |
1098 | return $ret; |
1099 | } |
1100 | |
db08d0c3 |
1101 | /** |
1102 | * Replaces non-braking spaces inserted by some browsers with regular space |
62f7daa5 |
1103 | * |
1104 | * This function can be used to replace non-braking space symbols |
1105 | * that are inserted in forms by some browsers instead of normal |
9af9c0a2 |
1106 | * space symbol. |
db08d0c3 |
1107 | * |
1108 | * @param string $string Text that needs to be cleaned |
1109 | * @param string $charset Charset used in text |
1110 | * @return string Cleaned text |
9af9c0a2 |
1111 | */ |
1112 | function cleanup_nbsp($string,$charset) { |
1113 | |
1114 | // reduce number of case statements |
1115 | if (stristr('iso-8859-',substr($charset,0,9))){ |
1116 | $output_charset="iso-8859-x"; |
1117 | } |
1118 | if (stristr('windows-125',substr($charset,0,11))){ |
1119 | $output_charset="cp125x"; |
1120 | } |
1121 | if (stristr('koi8',substr($charset,0,4))){ |
1122 | $output_charset="koi8-x"; |
1123 | } |
1124 | if (! isset($output_charset)){ |
1125 | $output_charset=strtolower($charset); |
1126 | } |
1127 | |
1128 | // where is non-braking space symbol |
1129 | switch($output_charset): |
1130 | case "iso-8859-x": |
97b9c02f |
1131 | case "cp125x": |
1132 | case "iso-2022-jp": |
9af9c0a2 |
1133 | $nbsp="\xA0"; |
1134 | break; |
9af9c0a2 |
1135 | case "koi8-x": |
1136 | $nbsp="\x9A"; |
1137 | break; |
1138 | case "utf-8": |
1139 | $nbsp="\xC2\xA0"; |
1140 | break; |
9af9c0a2 |
1141 | default: |
1142 | // don't change string if charset is unmatched |
1143 | return $string; |
1144 | endswitch; |
1145 | |
62f7daa5 |
1146 | // return space instead of non-braking space. |
9af9c0a2 |
1147 | return str_replace($nbsp,' ',$string); |
1148 | } |
4e519821 |
1149 | |
db08d0c3 |
1150 | /** |
1151 | * Function informs if it is safe to convert given charset to the one that is used by user. |
1152 | * |
62f7daa5 |
1153 | * It is safe to use conversion only if user uses utf-8 encoding and when |
db08d0c3 |
1154 | * converted charset is similar to the one that is used by user. |
1155 | * |
1156 | * @param string $input_charset Charset of text that needs to be converted |
1157 | * @return bool is it possible to convert to user's charset |
1158 | */ |
4e519821 |
1159 | function is_conversion_safe($input_charset) { |
6d3689f5 |
1160 | global $languages, $sm_notAlias, $default_charset, $lossy_encoding; |
33991968 |
1161 | |
6d3689f5 |
1162 | if (isset($lossy_encoding) && $lossy_encoding ) |
33991968 |
1163 | return true; |
4e519821 |
1164 | |
1165 | // convert to lower case |
1166 | $input_charset = strtolower($input_charset); |
1167 | |
1168 | // Is user's locale Unicode based ? |
1169 | if ( $default_charset == "utf-8" ) { |
1170 | return true; |
1171 | } |
1172 | |
1173 | // Charsets that are similar |
1174 | switch ($default_charset): |
1175 | case "windows-1251": |
62f7daa5 |
1176 | if ( $input_charset == "iso-8859-5" || |
03db90bc |
1177 | $input_charset == "koi8-r" || |
1178 | $input_charset == "koi8-u" ) { |
4e519821 |
1179 | return true; |
1180 | } else { |
1181 | return false; |
1182 | } |
1183 | case "windows-1257": |
62f7daa5 |
1184 | if ( $input_charset == "iso-8859-13" || |
03db90bc |
1185 | $input_charset == "iso-8859-4" ) { |
4e519821 |
1186 | return true; |
1187 | } else { |
1188 | return false; |
1189 | } |
1190 | case "iso-8859-4": |
62f7daa5 |
1191 | if ( $input_charset == "iso-8859-13" || |
03db90bc |
1192 | $input_charset == "windows-1257" ) { |
4e519821 |
1193 | return true; |
1194 | } else { |
1195 | return false; |
1196 | } |
1197 | case "iso-8859-5": |
62f7daa5 |
1198 | if ( $input_charset == "windows-1251" || |
1199 | $input_charset == "koi8-r" || |
03db90bc |
1200 | $input_charset == "koi8-u" ) { |
4e519821 |
1201 | return true; |
1202 | } else { |
1203 | return false; |
1204 | } |
1205 | case "iso-8859-13": |
1206 | if ( $input_charset == "iso-8859-4" || |
1207 | $input_charset == "windows-1257" ) { |
1208 | return true; |
1209 | } else { |
1210 | return false; |
1211 | } |
1212 | case "koi8-r": |
1213 | if ( $input_charset == "windows-1251" || |
62f7daa5 |
1214 | $input_charset == "iso-8859-5" || |
03db90bc |
1215 | $input_charset == "koi8-u" ) { |
4e519821 |
1216 | return true; |
1217 | } else { |
1218 | return false; |
1219 | } |
1220 | case "koi8-u": |
1221 | if ( $input_charset == "windows-1251" || |
03db90bc |
1222 | $input_charset == "iso-8859-5" || |
1223 | $input_charset == "koi8-r" ) { |
4e519821 |
1224 | return true; |
1225 | } else { |
1226 | return false; |
1227 | } |
1228 | default: |
1229 | return false; |
1230 | endswitch; |
1231 | } |
51468260 |
1232 | ?> |