advanced_tree: Fix for the IE fix that was breaking Opera7 and comments about tested...
[squirrelmail.git] / functions / i18n.php
CommitLineData
59177427 1<?php
1fd97780 2
35586184 3/**
4 * i18n.php
5 *
76911253 6 * Copyright (c) 1999-2003 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 *
15 * $Id$
16 */
17
961ca3d8 18require_once(SM_PATH . 'functions/global.php');
19
a2a7852b 20/* Decodes a string to the internal encoding from the given charset */
21function charset_decode ($charset, $string) {
6fbd125b 22 global $languages, $squirrelmail_language;
a2a7852b 23
3714db45 24 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
25 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 26 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
27 }
b05c8961 28
a2a7852b 29 /* All HTML special characters are 7 bit and can be replaced first */
cef054e4 30
098ea084 31 $string = htmlspecialchars ($string);
a2a7852b 32
33 $charset = strtolower($charset);
34
94965562 35 set_my_charset() ;
36
5dd23dac 37 /* controls cpu and memory intensive decoding cycles */
38 $agresive_decoding = false;
39
a2a7852b 40 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
41 if ($res[1] == '1') {
5dd23dac 42 include_once(SM_PATH . 'functions/decode/iso8859-1.php');
43 $ret = charset_decode_iso8859_1 ($string);
a2a7852b 44 } else if ($res[1] == '2') {
5dd23dac 45 include_once(SM_PATH . 'functions/decode/iso8859-2.php');
46 $ret = charset_decode_iso8859_2 ($string);
3a66bed2 47 } else if ($res[1] == '3') {
48 include_once(SM_PATH . 'functions/decode/iso8859-3.php');
49 $ret = charset_decode_iso8859_3 ($string);
9be313d5 50 } else if ($res[1] == '4') {
3a66bed2 51 include_once(SM_PATH . 'functions/decode/iso8859-4.php');
52 $ret = charset_decode_iso8859_4 ($string);
94965562 53 } else if ($res[1] == '5') {
3a66bed2 54 include_once(SM_PATH . 'functions/decode/iso8859-5.php');
55 $ret = charset_decode_iso8859_5 ($string);
ef82d2d5 56 } else if ($res[1] == '6') {
5dd23dac 57 include_once(SM_PATH . 'functions/decode/iso8859-6.php');
58 $ret = charset_decode_iso8859_6 ($string);
a2a7852b 59 } else if ($res[1] == '7') {
5dd23dac 60 include_once(SM_PATH . 'functions/decode/iso8859-7.php');
61 $ret = charset_decode_iso8859_7 ($string);
3a66bed2 62 } else if ($res[1] == '8') {
63 include_once(SM_PATH . 'functions/decode/iso8859-8.php');
64 $ret = charset_decode_iso8859_8 ($string);
3ab35042 65 } else if ($res[1] == '9') {
5dd23dac 66 include_once(SM_PATH . 'functions/decode/iso8859-9.php');
67 $ret = charset_decode_iso8859_9 ($string);
3a66bed2 68 } else if ($res[1] == '10') {
69 include_once(SM_PATH . 'functions/decode/iso8859-10.php');
70 $ret = charset_decode_iso8859_10 ($string);
71 } else if ($res[1] == '11') {
72 include_once(SM_PATH . 'functions/decode/iso8859-11.php');
73 $ret = charset_decode_iso8859_11 ($string);
9be313d5 74 } else if ($res[1] == '13') {
3a66bed2 75 include_once(SM_PATH . 'functions/decode/iso8859-13.php');
76 $ret = charset_decode_iso8859_13 ($string);
77 } else if ($res[1] == '14') {
78 include_once(SM_PATH . 'functions/decode/iso8859-14.php');
79 $ret = charset_decode_iso8859_14 ($string);
a2a7852b 80 } else if ($res[1] == '15') {
5dd23dac 81 include_once(SM_PATH . 'functions/decode/iso8859-15.php');
82 $ret = charset_decode_iso8859_15 ($string);
3a66bed2 83 } else if ($res[1] == '16') {
84 include_once(SM_PATH . 'functions/decode/iso8859-16.php');
85 $ret = charset_decode_iso8859_16 ($string);
a2a7852b 86 } else {
87 $ret = charset_decode_iso_8859_default ($string);
88 }
89 } else if ($charset == 'ns_4551-1') {
90 $ret = charset_decode_ns_4551_1 ($string);
91 } else if ($charset == 'koi8-r') {
5dd23dac 92 include_once(SM_PATH . 'functions/decode/koi8-r.php');
a2a7852b 93 $ret = charset_decode_koi8r ($string);
1c0e847f 94 } else if ($charset == 'koi8-u') {
5dd23dac 95 include_once(SM_PATH . 'functions/decode/koi8-u.php');
1c0e847f 96 $ret = charset_decode_koi8u ($string);
5dd23dac 97 } else if ($charset == 'windows-1250') {
98 include_once(SM_PATH . 'functions/decode/cp1250.php');
99 $ret = charset_decode_cp1250 ($string);
a2a7852b 100 } else if ($charset == 'windows-1251') {
5dd23dac 101 include_once(SM_PATH . 'functions/decode/cp1251.php');
102 $ret = charset_decode_cp1251 ($string);
103 } else if ($charset == 'windows-1252') {
104 include_once(SM_PATH . 'functions/decode/cp1252.php');
105 $ret = charset_decode_cp1252 ($string);
3ab35042 106 } else if ($charset == 'windows-1253') {
5dd23dac 107 include_once(SM_PATH . 'functions/decode/cp1253.php');
108 $ret = charset_decode_cp1253 ($string);
3ab35042 109 } else if ($charset == 'windows-1254') {
5dd23dac 110 include_once(SM_PATH . 'functions/decode/cp1254.php');
111 $ret = charset_decode_cp1254 ($string);
c48a8ca7 112 } else if ($charset == 'windows-1255') {
5dd23dac 113 include_once(SM_PATH . 'functions/decode/cp1255.php');
114 $ret = charset_decode_cp1255 ($string);
c48a8ca7 115 } else if ($charset == 'windows-1256') {
5dd23dac 116 include_once(SM_PATH . 'functions/decode/cp1256.php');
117 $ret = charset_decode_cp1256 ($string);
c37a12f8 118 } else if ($charset == 'windows-1257') {
3a66bed2 119 include_once(SM_PATH . 'functions/decode/cp1257.php');
120 $ret = charset_decode_cp1257 ($string);
5dd23dac 121 } else if ($charset == 'windows-1258') {
122 include_once(SM_PATH . 'functions/decode/cp1258.php');
123 $ret = charset_decode_cp1258 ($string);
124 } else if ($charset == 'big5' and $agresive_decoding ) {
125 include_once(SM_PATH . 'functions/decode/big5.php');
126 $ret = charset_decode_big5 ($string);
127 } else if ($charset == 'gb2312' and $agresive_decoding ) {
128 include_once(SM_PATH . 'functions/decode/gb2312.php');
129 $ret = charset_decode_gb2312 ($string);
3ab35042 130 } else if ($charset == 'utf-8') {
5dd23dac 131 include_once(SM_PATH . 'functions/decode/utf-8.php');
3ab35042 132 $ret = charset_decode_utf8 ($string);
a2a7852b 133 } else {
134 $ret = $string;
135 }
136 return( $ret );
137}
138
a2a7852b 139
140/* Remove all 8 bit characters from all other ISO-8859 character sets */
141function charset_decode_iso_8859_default ($string) {
142 return (strtr($string, "\240\241\242\243\244\245\246\247".
1fd97780 143 "\250\251\252\253\254\255\256\257".
144 "\260\261\262\263\264\265\266\267".
145 "\270\271\272\273\274\275\276\277".
146 "\300\301\302\303\304\305\306\307".
147 "\310\311\312\313\314\315\316\317".
148 "\320\321\322\323\324\325\326\327".
149 "\330\331\332\333\334\335\336\337".
150 "\340\341\342\343\344\345\346\347".
151 "\350\351\352\353\354\355\356\357".
152 "\360\361\362\363\364\365\366\367".
a2a7852b 153 "\370\371\372\373\374\375\376\377",
1fd97780 154 "????????????????????????????????????????".
155 "????????????????????????????????????????".
156 "????????????????????????????????????????".
157 "????????"));
a2a7852b 158
159}
160
161/*
162 * This is the same as ISO-646-NO and is used by some
163 * Microsoft programs when sending Norwegian characters
164 */
165function charset_decode_ns_4551_1 ($string) {
166 /*
167 * These characters are:
168 * Latin capital letter AE
169 * Latin capital letter O with stroke
170 * Latin capital letter A with ring above
171 * and the same as small letters
172 */
173 return strtr ($string, "[\\]{|}", "");
174}
175
6fbd125b 176
a2a7852b 177/*
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
181 */
67a8c90a 182function set_up_language($sm_language, $do_search = false, $default = false) {
a2a7852b 183
184 static $SetupAlready = 0;
9eb0fbd4 185 global $use_gettext, $languages,
a2a7852b 186 $squirrelmail_language, $squirrelmail_default_language,
187 $sm_notAlias;
188
189 if ($SetupAlready) {
190 return;
191 }
a65846a7 192
5c920668 193 $SetupAlready = TRUE;
961ca3d8 194 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
a2a7852b 195
961ca3d8 196 if ($do_search && ! $sm_language && isset($accept_lang)) {
197 $sm_language = substr($accept_lang, 0, 2);
a2a7852b 198 }
66d7950f 199
67a8c90a 200 if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
a2a7852b 201 $squirrelmail_language = $squirrelmail_default_language;
66d7950f 202 $sm_language = $squirrelmail_default_language;
a2a7852b 203 }
204 $sm_notAlias = $sm_language;
205 while (isset($languages[$sm_notAlias]['ALIAS'])) {
206 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
207 }
208
88cb1b4d 209 if ( isset($sm_language) &&
5c920668 210 $use_gettext &&
211 $sm_language != '' &&
212 isset($languages[$sm_notAlias]['CHARSET']) ) {
a65846a7 213 bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
88cb1b4d 214 textdomain( 'squirrelmail' );
7928848f 215 if (function_exists('bind_textdomain_codeset')) {
216 bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
217 }
f2374580 218 if (isset($languages[$sm_notAlias]['LOCALE'])){
219 $longlocale=$languages[$sm_notAlias]['LOCALE'];
220 } else {
221 $longlocale=$sm_notAlias;
222 }
88cb1b4d 223 if ( !ini_get('safe_mode') &&
f2374580 224 getenv( 'LC_ALL' ) != $longlocale ) {
225 putenv( "LC_ALL=$longlocale" );
226 putenv( "LANG=$longlocale" );
227 putenv( "LANGUAGE=$longlocale" );
a2a7852b 228 }
f2374580 229 setlocale(LC_ALL, $longlocale);
230 $squirrelmail_language = $sm_notAlias;
538f1ab7 231 if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
b05c8961 232 header ('Content-Type: text/html; charset=EUC-JP');
233 if (!function_exists('mb_internal_encoding')) {
e842b215 234 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --enable-mbstring).");
235 }
236 if (function_exists('mb_language')) {
237 mb_language('Japanese');
b05c8961 238 }
239 mb_internal_encoding('EUC-JP');
240 mb_http_output('pass');
241 } else {
5c920668 242 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
a2a7852b 243 }
244}
b05c8961 245}
a2a7852b 246
247function set_my_charset(){
248
249 /*
250 * There can be a $default_charset setting in the
251 * config.php file, but the user may have a different language
252 * selected for a user interface. This function checks the
253 * language selected by the user and tags the outgoing messages
254 * with the appropriate charset corresponding to the language
255 * selection. This is "more right" (tm), than just stamping the
256 * message blindly with the system-wide $default_charset.
257 */
94965562 258 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
88cb1b4d 259
a2a7852b 260 $my_language = getPref($data_dir, $username, 'language');
5c920668 261 if (!$my_language) {
94965562 262 $my_language = $squirrelmail_default_language ;
5c920668 263 }
a2a7852b 264 while (isset($languages[$my_language]['ALIAS'])) {
f7e8861e 265 $my_language = $languages[$my_language]['ALIAS'];
a2a7852b 266 }
5c920668 267 $my_charset = $languages[$my_language]['CHARSET'];
a2a7852b 268 if ($my_charset) {
269 $default_charset = $my_charset;
270 }
271}
272
a2a7852b 273/* ------------------------------ main --------------------------- */
274
5c920668 275global $squirrelmail_language, $languages, $use_gettext;
276
a2a7852b 277if (! isset($squirrelmail_language)) {
278 $squirrelmail_language = '';
279}
280
281/* This array specifies the available languages. */
5c920668 282
ddc315a7 283if ( file_exists( SM_PATH . 'locale/ca_ES') ) {
284 // The glibc locale is ca_ES.
285 $languages['ca_ES']['NAME'] = 'Catalan';
286 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
287 $languages['ca']['ALIAS'] = 'ca_ES';
288}
a2a7852b 289
ddc315a7 290if ( file_exists( SM_PATH . 'locale/cs_CZ') ) {
291 $languages['cs_CZ']['NAME'] = 'Czech';
292 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
293 $languages['cs']['ALIAS'] = 'cs_CZ';
294}
5c920668 295
ddc315a7 296if ( file_exists( SM_PATH . 'locale/da_DK') ) {
297 // Danish locale is da_DK.
298 $languages['da_DK']['NAME'] = 'Danish';
299 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
300 $languages['da']['ALIAS'] = 'da_DK';
301}
5c920668 302
ddc315a7 303if ( file_exists( SM_PATH . 'locale/de_DE') ) {
304 $languages['de_DE']['NAME'] = 'Deutsch';
305 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
306 $languages['de']['ALIAS'] = 'de_DE';
307}
a2a7852b 308
5c920668 309// There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
310// but who cares about !US, right? Right? :)
a2a7852b 311
ddc315a7 312if ( file_exists( SM_PATH . 'locale/el_GR') ) {
313 $languages['el_GR']['NAME'] = 'Greek';
314 $languages['el_GR']['CHARSET'] = 'iso-8859-7';
315 $languages['el']['ALIAS'] = 'el_GR';
316}
3ab35042 317
5c920668 318$languages['en_US']['NAME'] = 'English';
319$languages['en_US']['CHARSET'] = 'iso-8859-1';
320$languages['en']['ALIAS'] = 'en_US';
a2a7852b 321
ddc315a7 322if ( file_exists( SM_PATH . 'locale/es_ES') ) {
323 $languages['es_ES']['NAME'] = 'Spanish';
324 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
325 $languages['es']['ALIAS'] = 'es_ES';
326}
327if ( file_exists( SM_PATH . 'locale/et_EE') ) {
328 $languages['et_EE']['NAME'] = 'Estonian';
329 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
330 $languages['et']['ALIAS'] = 'et_EE';
331}
332if ( file_exists( SM_PATH . 'locale/fo_FO') ) {
333 $languages['fo_FO']['NAME'] = 'Faroese';
334 $languages['fo_FO']['CHARSET'] = 'iso-8859-1';
335 $languages['fo']['ALIAS'] = 'fo_FO';
336}
337if ( file_exists( SM_PATH . 'locale/fi_FI') ) {
338 $languages['fi_FI']['NAME'] = 'Finnish';
339 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
340 $languages['fi']['ALIAS'] = 'fi_FI';
341}
342if ( file_exists( SM_PATH . 'locale/fr_FR') ) {
343 $languages['fr_FR']['NAME'] = 'French';
344 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
345 $languages['fr']['ALIAS'] = 'fr_FR';
346}
347if ( file_exists( SM_PATH . 'locale/hr_HR') ) {
348 $languages['hr_HR']['NAME'] = 'Croatian';
349 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
350 $languages['hr']['ALIAS'] = 'hr_HR';
351}
352if ( file_exists( SM_PATH . 'locale/hu_HU') ) {
353 $languages['hu_HU']['NAME'] = 'Hungarian';
354 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
355 $languages['hu']['ALIAS'] = 'hu_HU';
356}
357if ( file_exists( SM_PATH . 'locale/id_ID') ) {
358 $languages['id_ID']['NAME'] = 'Bahasa Indonesia';
359 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
360 $languages['id']['ALIAS'] = 'id_ID';
361}
362if ( file_exists( SM_PATH . 'locale/is_IS') ) {
363 $languages['is_IS']['NAME'] = 'Icelandic';
364 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
365 $languages['is']['ALIAS'] = 'is_IS';
366}
367if ( file_exists( SM_PATH . 'locale/it_IT') ) {
368 $languages['it_IT']['NAME'] = 'Italian';
369 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
370 $languages['it']['ALIAS'] = 'it_IT';
371}
372if ( file_exists( SM_PATH . 'locale/ja_JP') ) {
373 $languages['ja_JP']['NAME'] = 'Japanese';
374 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
375 $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
376 $languages['ja']['ALIAS'] = 'ja_JP';
377}
378if ( file_exists( SM_PATH . 'locale/ko_KR') ) {
379 $languages['ko_KR']['NAME'] = 'Korean';
380 $languages['ko_KR']['CHARSET'] = 'euc-KR';
381 $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
382 $languages['ko']['ALIAS'] = 'ko_KR';
383}
384if ( file_exists( SM_PATH . 'locale/nl_NL') ) {
385 $languages['nl_NL']['NAME'] = 'Dutch';
386 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
387 $languages['nl']['ALIAS'] = 'nl_NL';
388}
389if ( file_exists( SM_PATH . 'locale/no_NO') ) {
390 $languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
391 $languages['no_NO']['CHARSET'] = 'iso-8859-1';
392 $languages['no']['ALIAS'] = 'no_NO';
393}
394if ( file_exists( SM_PATH . 'locale/nn_NO') ) {
395 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
396 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
397}
398if ( file_exists( SM_PATH . 'locale/pl_PL') ) {
399 $languages['pl_PL']['NAME'] = 'Polish';
400 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
401 $languages['pl']['ALIAS'] = 'pl_PL';
402}
403if ( file_exists( SM_PATH . 'locale/pt_PT') ) {
404 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
405 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
406 $languages['pt']['ALIAS'] = 'pt_PT';
407}
408if ( file_exists( SM_PATH . 'locale/pt_BR') ) {
409 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
410 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
411}
412if ( file_exists( SM_PATH . 'locale/ru_RU') ) {
413 $languages['ru_RU']['NAME'] = 'Russian';
414 $languages['ru_RU']['CHARSET'] = 'koi8-r';
415 $languages['ru_RU']['LOCALE'] = 'ru_RU.KOI8-R';
416 $languages['ru']['ALIAS'] = 'ru_RU';
417}
418if ( file_exists( SM_PATH . 'locale/sr_YU') ) {
419 $languages['sr_YU']['NAME'] = 'Serbian';
420 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
421 $languages['sr']['ALIAS'] = 'sr_YU';
422}
423if ( file_exists( SM_PATH . 'locale/sv_SE') ) {
424 $languages['sv_SE']['NAME'] = 'Swedish';
425 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
426 $languages['sv']['ALIAS'] = 'sv_SE';
427}
428if ( file_exists( SM_PATH . 'locale/tr_TR') ) {
429 $languages['tr_TR']['NAME'] = 'Turkish';
430 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
431 $languages['tr']['ALIAS'] = 'tr_TR';
432}
433if ( file_exists( SM_PATH . 'locale/zh_TW') ) {
434 $languages['zh_TW']['NAME'] = 'Chinese Trad';
435 $languages['zh_TW']['CHARSET'] = 'big5';
436 $languages['tw']['ALIAS'] = 'zh_TW';
437}
438if ( file_exists( SM_PATH . 'locale/zh_CN') ) {
439 $languages['zh_CN']['NAME'] = 'Chinese Simp';
440 $languages['zh_CN']['CHARSET'] = 'gb2312';
441 $languages['cn']['ALIAS'] = 'zh_CN';
442}
443if ( file_exists( SM_PATH . 'locale/sk_SK') ) {
444 $languages['sk_SK']['NAME'] = 'Slovak';
445 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
446 $languages['sk']['ALIAS'] = 'sk_SK';
447}
448if ( file_exists( SM_PATH . 'locale/ro_RO') ) {
449 $languages['ro_RO']['NAME'] = 'Romanian';
450 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
451 $languages['ro']['ALIAS'] = 'ro_RO';
452}
453if ( file_exists( SM_PATH . 'locale/th_TH') ) {
454 $languages['th_TH']['NAME'] = 'Thai';
455 $languages['th_TH']['CHARSET'] = 'tis-620';
456 $languages['th']['ALIAS'] = 'th_TH';
457}
458if ( file_exists( SM_PATH . 'locale/lt_LT') ) {
459 $languages['lt_LT']['NAME'] = 'Lithuanian';
e515e3b0 460 $languages['lt_LT']['CHARSET'] = 'iso-8859-4';
461 $languages['lt_LT']['LOCALE'] = 'lt_LT.ISO-8859-4';
ddc315a7 462 $languages['lt']['ALIAS'] = 'lt_LT';
463}
464if ( file_exists( SM_PATH . 'locale/sl_SI') ) {
465 $languages['sl_SI']['NAME'] = 'Slovenian';
466 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
467 $languages['sl']['ALIAS'] = 'sl_SI';
468}
469if ( file_exists( SM_PATH . 'locale/bg_BG') ) {
470 $languages['bg_BG']['NAME'] = 'Bulgarian';
471 $languages['bg_BG']['CHARSET'] = 'windows-1251';
472 $languages['bg']['ALIAS'] = 'bg_BG';
473}
474if ( file_exists( SM_PATH . 'locale/uk_UA') ) {
475 $languages['uk_UA']['NAME'] = 'Ukrainian';
476 $languages['uk_UA']['CHARSET'] = 'koi8-u';
477 $languages['uk']['ALIAS'] = 'uk_UA';
478}
479if ( file_exists( SM_PATH . 'locale/cy_GB') ) {
480 $languages['cy_GB']['NAME'] = 'Welsh';
481 $languages['cy_GB']['CHARSET'] = 'iso-8859-1';
482 $languages['cy']['ALIAS'] = 'cy_GB';
483}
484if ( file_exists( SM_PATH . 'locale/vi_VN') ) {
485 $languages['vi_VN']['NAME'] = 'Vietnamese';
486 $languages['vi_VN']['CHARSET'] = 'utf-8';
487 $languages['vi']['ALIAS'] = 'vi_VN';
488}
d3b57948 489// Right to left languages
ddc315a7 490if ( file_exists( SM_PATH . 'locale/ar') ) {
491 $languages['ar']['NAME'] = 'Arabic';
492 $languages['ar']['CHARSET'] = 'windows-1256';
493 $languages['ar']['DIR'] = 'rtl';
494}
495if ( file_exists( SM_PATH . 'locale/he_IL') ) {
496 $languages['he_IL']['NAME'] = 'Hebrew';
497 $languages['he_IL']['CHARSET'] = 'windows-1255';
498 $languages['he_IL']['DIR'] = 'rtl';
499 $languages['he']['ALIAS'] = 'he_IL';
500}
d3b57948 501
5c920668 502/* Detect whether gettext is installed. */
a2a7852b 503$gettext_flags = 0;
504if (function_exists('_')) {
505 $gettext_flags += 1;
506}
507if (function_exists('bindtextdomain')) {
508 $gettext_flags += 2;
509}
510if (function_exists('textdomain')) {
511 $gettext_flags += 4;
512}
513
5c920668 514/* If gettext is fully loaded, cool */
a2a7852b 515if ($gettext_flags == 7) {
516 $use_gettext = true;
517}
5c920668 518/* If we can fake gettext, try that */
a2a7852b 519elseif ($gettext_flags == 0) {
520 $use_gettext = true;
e7ab8c9d 521 include_once(SM_PATH . 'functions/gettext.php');
a2a7852b 522} else {
5c920668 523 /* Uh-ho. A weird install */
a2a7852b 524 if (! $gettext_flags & 1) {
525 function _($str) {
526 return $str;
527 }
528 }
529 if (! $gettext_flags & 2) {
530 function bindtextdomain() {
531 return;
532 }
533 }
534 if (! $gettext_flags & 4) {
535 function textdomain() {
536 return;
537 }
538 }
539}
540
1d33e35e 541
542/*
543 * Japanese charset extra function
544 *
545 */
546function japanese_charset_xtra() {
547 $ret = func_get_arg(1); /* default return value */
548 if (function_exists('mb_detect_encoding')) {
549 switch (func_get_arg(0)) { /* action */
550 case 'decode':
e842b215 551 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 552 if ($detect_encoding == 'JIS' ||
553 $detect_encoding == 'EUC-JP' ||
e842b215 554 $detect_encoding == 'SJIS' ||
555 $detect_encoding == 'UTF-8') {
1d33e35e 556
e842b215 557 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
1d33e35e 558 }
559 break;
560 case 'encode':
e842b215 561 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 562 if ($detect_encoding == 'JIS' ||
563 $detect_encoding == 'EUC-JP' ||
e842b215 564 $detect_encoding == 'SJIS' ||
565 $detect_encoding == 'UTF-8') {
1d33e35e 566
e842b215 567 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
1d33e35e 568 }
569 break;
570 case 'strimwidth':
571 $width = func_get_arg(2);
572 $ret = mb_strimwidth($ret, 0, $width, '...');
573 break;
574 case 'encodeheader':
8ba05cbe 575 $result = '';
576 if (strlen($ret) > 0) {
577 $tmpstr = mb_substr($ret, 0, 1);
578 $prevcsize = strlen($tmpstr);
579 for ($i = 1; $i < mb_strlen($ret); $i++) {
580 $tmp = mb_substr($ret, $i, 1);
581 if (strlen($tmp) == $prevcsize) {
582 $tmpstr .= $tmp;
583 } else {
584 if ($prevcsize == 1) {
585 $result .= $tmpstr;
586 } else {
e842b215 587 $result .= str_replace(' ', '',
588 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 589 }
590 $tmpstr = $tmp;
591 $prevcsize = strlen($tmp);
592 }
593 }
594 if (strlen($tmpstr)) {
595 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
596 $result .= $tmpstr;
597 else
e842b215 598 $result .= str_replace(' ', '',
599 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 600 }
601 }
602 $ret = $result;
1d33e35e 603 break;
604 case 'decodeheader':
605 $ret = str_replace("\t", "", $ret);
606 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
e842b215 607 $ret = @mb_decode_mimeheader($ret);
608 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1d33e35e 609 break;
610 case 'downloadfilename':
611 $useragent = func_get_arg(2);
612 if (strstr($useragent, 'Windows') !== false ||
613 strstr($useragent, 'Mac_') !== false) {
614 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
615 } else {
616 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
617}
618 break;
e842b215 619 case 'wordwrap':
620 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
621 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
622 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
623 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
624 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
625 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
626 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
627 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
628 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
629 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
630 $wrap = func_get_arg(2);
631
632 if (strlen($ret) >= $wrap &&
633 substr($ret, 0, 1) != '>' &&
634 strpos($ret, 'http://') === FALSE &&
635 strpos($ret, 'https://') === FALSE &&
636 strpos($ret, 'ftp://') === FALSE) {
637
638 $ret = mb_convert_kana($ret, "KV");
639
640 $line_new = '';
641 $ptr = 0;
642
643 while ($ptr < strlen($ret) - 1) {
644 $l = mb_strcut($ret, $ptr, $wrap);
645 $ptr += strlen($l);
646 $tmp = $l;
647
648 $l = mb_strcut($ret, $ptr, 2);
649 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
650 $tmp .= $l;
651 $ptr += strlen($l);
652 $l = mb_strcut($ret, $ptr, 1);
653 }
654 $line_new .= $tmp;
655 if ($ptr < strlen($ret) - 1)
656 $line_new .= "\n";
657 }
658 $ret = $line_new;
659 }
660 break;
661 case 'utf7-imap_encode':
662 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
663 break;
664 case 'utf7-imap_decode':
665 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
666 break;
1d33e35e 667 }
668 }
669 return $ret;
670}
671
672
673/*
674 * Korean charset extra function
675 * Hangul(Korean Character) Attached File Name Fix.
676 */
677function korean_charset_xtra() {
678
679 $ret = func_get_arg(1); /* default return value */
680 if (func_get_arg(0) == 'downloadfilename') { /* action */
681 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
682 for ($i=0;$i<strlen($ret);$i++) {
683 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
684 $i++;
685 continue;
686 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
687 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
688 ($ret[$i] == '.') || ($ret[$i] == '-')) {
689 continue;
690 } else {
691 $ret[$i] = '_';
692 }
693 }
694
695 }
696
697 return $ret;
698}
699
9af9c0a2 700/*
701 * This function can be used to replace non-braking space symbols
702 * that are inserted in forms by some browsers instead of normal
703 * space symbol.
704 */
705function cleanup_nbsp($string,$charset) {
706
707 // reduce number of case statements
708 if (stristr('iso-8859-',substr($charset,0,9))){
709 $output_charset="iso-8859-x";
710 }
711 if (stristr('windows-125',substr($charset,0,11))){
712 $output_charset="cp125x";
713 }
714 if (stristr('koi8',substr($charset,0,4))){
715 $output_charset="koi8-x";
716 }
717 if (! isset($output_charset)){
718 $output_charset=strtolower($charset);
719 }
720
721// where is non-braking space symbol
722switch($output_charset):
723 case "iso-8859-x":
97b9c02f 724 case "cp125x":
725 case "iso-2022-jp":
9af9c0a2 726 $nbsp="\xA0";
727 break;
9af9c0a2 728 case "koi8-x":
729 $nbsp="\x9A";
730 break;
731 case "utf-8":
732 $nbsp="\xC2\xA0";
733 break;
9af9c0a2 734 default:
735 // don't change string if charset is unmatched
736 return $string;
737endswitch;
738
739// return space instead of non-braking space.
740 return str_replace($nbsp,' ',$string);
741}
e842b215 742?>