removing help translations. th_TH
[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) {
3ec81e63 22 global $languages, $squirrelmail_language, $default_charset;
edf2c0ba 23 global $use_php_recode, $use_php_iconv, $agresive_decoding;
a2a7852b 24
3714db45 25 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
26 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 27 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
28 }
b05c8961 29
3ec81e63 30 $charset = strtolower($charset);
31
32 set_my_charset();
33
34 // Variables that allow to use functions without function_exist() calls
edf2c0ba 35 if (! isset($use_php_recode) || $use_php_recode=="" ) {
36 $use_php_recode=false; }
37 if (! isset($use_php_iconv) || $use_php_iconv=="" ) {
38 $use_php_iconv=false; }
3ec81e63 39
40 // Don't do conversion if charset is the same.
41 if ( $charset == strtolower($default_charset) )
42 return htmlspecialchars($string);
43
44 // catch iso-8859-8-i thing
45 if ( $charset == "iso-8859-8-i" )
46 $charset = "iso-8859-8";
47
48 /*
49 * Recode converts html special characters automatically if you use
50 * 'charset..html' decoding. There is no documented way to put -d option
51 * into php recode function call.
52 */
53 if ( $use_php_recode ) {
54 if ( $default_charset == "utf-8" ) {
55 // other charsets can be converted to utf-8 without loss.
56 // and output string is smaller
57 $string = recode_string($charset . "..utf-8",$string);
58 return htmlspecialchars($string);
59 } else {
60 $string = recode_string($charset . "..html",$string);
61 // recode does not convert single quote, htmlspecialchars does.
62 $string = str_replace("'", '&#039;', $string);
63 return $string;
64 }
65 }
66
67 // iconv functions does not have html target and can be used only with utf-8
68 if ( $use_php_iconv && $default_charset=='utf-8') {
69 $string = iconv($charset,$default_charset,$string);
70 return htmlspecialchars($string);
71 }
72
73 // If we don't use recode and iconv, we'll do it old way.
74
a2a7852b 75 /* All HTML special characters are 7 bit and can be replaced first */
cef054e4 76
098ea084 77 $string = htmlspecialchars ($string);
a2a7852b 78
5dd23dac 79 /* controls cpu and memory intensive decoding cycles */
edf2c0ba 80 if (! isset($agresive_decoding) || $agresive_decoding=="" ) {
81 $agresive_decoding=false; }
5dd23dac 82
a2a7852b 83 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
84 if ($res[1] == '1') {
5dd23dac 85 include_once(SM_PATH . 'functions/decode/iso8859-1.php');
86 $ret = charset_decode_iso8859_1 ($string);
a2a7852b 87 } else if ($res[1] == '2') {
5dd23dac 88 include_once(SM_PATH . 'functions/decode/iso8859-2.php');
89 $ret = charset_decode_iso8859_2 ($string);
3a66bed2 90 } else if ($res[1] == '3') {
91 include_once(SM_PATH . 'functions/decode/iso8859-3.php');
92 $ret = charset_decode_iso8859_3 ($string);
9be313d5 93 } else if ($res[1] == '4') {
3a66bed2 94 include_once(SM_PATH . 'functions/decode/iso8859-4.php');
95 $ret = charset_decode_iso8859_4 ($string);
94965562 96 } else if ($res[1] == '5') {
3a66bed2 97 include_once(SM_PATH . 'functions/decode/iso8859-5.php');
98 $ret = charset_decode_iso8859_5 ($string);
ef82d2d5 99 } else if ($res[1] == '6') {
5dd23dac 100 include_once(SM_PATH . 'functions/decode/iso8859-6.php');
101 $ret = charset_decode_iso8859_6 ($string);
a2a7852b 102 } else if ($res[1] == '7') {
5dd23dac 103 include_once(SM_PATH . 'functions/decode/iso8859-7.php');
104 $ret = charset_decode_iso8859_7 ($string);
3a66bed2 105 } else if ($res[1] == '8') {
106 include_once(SM_PATH . 'functions/decode/iso8859-8.php');
107 $ret = charset_decode_iso8859_8 ($string);
3ab35042 108 } else if ($res[1] == '9') {
5dd23dac 109 include_once(SM_PATH . 'functions/decode/iso8859-9.php');
110 $ret = charset_decode_iso8859_9 ($string);
3a66bed2 111 } else if ($res[1] == '10') {
112 include_once(SM_PATH . 'functions/decode/iso8859-10.php');
113 $ret = charset_decode_iso8859_10 ($string);
114 } else if ($res[1] == '11') {
115 include_once(SM_PATH . 'functions/decode/iso8859-11.php');
116 $ret = charset_decode_iso8859_11 ($string);
9be313d5 117 } else if ($res[1] == '13') {
3a66bed2 118 include_once(SM_PATH . 'functions/decode/iso8859-13.php');
119 $ret = charset_decode_iso8859_13 ($string);
120 } else if ($res[1] == '14') {
121 include_once(SM_PATH . 'functions/decode/iso8859-14.php');
122 $ret = charset_decode_iso8859_14 ($string);
a2a7852b 123 } else if ($res[1] == '15') {
5dd23dac 124 include_once(SM_PATH . 'functions/decode/iso8859-15.php');
125 $ret = charset_decode_iso8859_15 ($string);
3a66bed2 126 } else if ($res[1] == '16') {
127 include_once(SM_PATH . 'functions/decode/iso8859-16.php');
128 $ret = charset_decode_iso8859_16 ($string);
a2a7852b 129 } else {
130 $ret = charset_decode_iso_8859_default ($string);
131 }
132 } else if ($charset == 'ns_4551-1') {
133 $ret = charset_decode_ns_4551_1 ($string);
134 } else if ($charset == 'koi8-r') {
5dd23dac 135 include_once(SM_PATH . 'functions/decode/koi8-r.php');
a2a7852b 136 $ret = charset_decode_koi8r ($string);
1c0e847f 137 } else if ($charset == 'koi8-u') {
5dd23dac 138 include_once(SM_PATH . 'functions/decode/koi8-u.php');
1c0e847f 139 $ret = charset_decode_koi8u ($string);
5dd23dac 140 } else if ($charset == 'windows-1250') {
141 include_once(SM_PATH . 'functions/decode/cp1250.php');
142 $ret = charset_decode_cp1250 ($string);
a2a7852b 143 } else if ($charset == 'windows-1251') {
5dd23dac 144 include_once(SM_PATH . 'functions/decode/cp1251.php');
145 $ret = charset_decode_cp1251 ($string);
146 } else if ($charset == 'windows-1252') {
147 include_once(SM_PATH . 'functions/decode/cp1252.php');
148 $ret = charset_decode_cp1252 ($string);
3ab35042 149 } else if ($charset == 'windows-1253') {
5dd23dac 150 include_once(SM_PATH . 'functions/decode/cp1253.php');
151 $ret = charset_decode_cp1253 ($string);
3ab35042 152 } else if ($charset == 'windows-1254') {
5dd23dac 153 include_once(SM_PATH . 'functions/decode/cp1254.php');
154 $ret = charset_decode_cp1254 ($string);
c48a8ca7 155 } else if ($charset == 'windows-1255') {
5dd23dac 156 include_once(SM_PATH . 'functions/decode/cp1255.php');
157 $ret = charset_decode_cp1255 ($string);
c48a8ca7 158 } else if ($charset == 'windows-1256') {
5dd23dac 159 include_once(SM_PATH . 'functions/decode/cp1256.php');
160 $ret = charset_decode_cp1256 ($string);
c37a12f8 161 } else if ($charset == 'windows-1257') {
3a66bed2 162 include_once(SM_PATH . 'functions/decode/cp1257.php');
163 $ret = charset_decode_cp1257 ($string);
5dd23dac 164 } else if ($charset == 'windows-1258') {
165 include_once(SM_PATH . 'functions/decode/cp1258.php');
166 $ret = charset_decode_cp1258 ($string);
e9a71964 167 } else if ($charset == 'x-mac-roman') {
168 include_once(SM_PATH . 'functions/decode/cp10000.php');
169 $ret = charset_decode_cp10000 ($string);
170 } else if ($charset == 'x-mac-greek') {
171 include_once(SM_PATH . 'functions/decode/cp10006.php');
172 $ret = charset_decode_cp10006 ($string);
173 } else if ($charset == 'x-mac-cyrillic') {
174 include_once(SM_PATH . 'functions/decode/cp10007.php');
175 $ret = charset_decode_cp10007 ($string);
176 } else if ($charset == 'x-mac-ukrainian') {
177 include_once(SM_PATH . 'functions/decode/cp10017.php');
178 $ret = charset_decode_cp10017 ($string);
179 } else if ($charset == 'x-mac-centraleurroman') {
180 include_once(SM_PATH . 'functions/decode/cp10029.php');
181 $ret = charset_decode_cp10029 ($string);
182 } else if ($charset == 'x-mac-icelandic') {
183 include_once(SM_PATH . 'functions/decode/cp10079.php');
184 $ret = charset_decode_cp10079 ($string);
185 } else if ($charset == 'x-mac-turkish') {
186 include_once(SM_PATH . 'functions/decode/cp10081.php');
187 $ret = charset_decode_cp10081 ($string);
188 } else if ($charset == 'ibm855') {
189 include_once(SM_PATH . 'functions/decode/cp855.php');
190 $ret = charset_decode_cp855 ($string);
191 } else if ($charset == 'ibm866') {
192 include_once(SM_PATH . 'functions/decode/cp866.php');
193 $ret = charset_decode_cp866 ($string);
0e4337e7 194 } else if ($charset == 'iso-ir-111') {
195 include_once(SM_PATH . 'functions/decode/iso-ir-111.php');
196 $ret = charset_decode_iso_ir_111 ($string);
7af26ef8 197 } else if ($charset == 'tis-620') {
198 include_once(SM_PATH . 'functions/decode/tis620.php');
199 $ret = charset_decode_tis620 ($string);
5dd23dac 200 } else if ($charset == 'big5' and $agresive_decoding ) {
201 include_once(SM_PATH . 'functions/decode/big5.php');
202 $ret = charset_decode_big5 ($string);
203 } else if ($charset == 'gb2312' and $agresive_decoding ) {
204 include_once(SM_PATH . 'functions/decode/gb2312.php');
205 $ret = charset_decode_gb2312 ($string);
3ab35042 206 } else if ($charset == 'utf-8') {
5dd23dac 207 include_once(SM_PATH . 'functions/decode/utf-8.php');
3ab35042 208 $ret = charset_decode_utf8 ($string);
a2a7852b 209 } else {
210 $ret = $string;
211 }
212 return( $ret );
213}
214
a2a7852b 215
216/* Remove all 8 bit characters from all other ISO-8859 character sets */
217function charset_decode_iso_8859_default ($string) {
218 return (strtr($string, "\240\241\242\243\244\245\246\247".
1fd97780 219 "\250\251\252\253\254\255\256\257".
220 "\260\261\262\263\264\265\266\267".
221 "\270\271\272\273\274\275\276\277".
222 "\300\301\302\303\304\305\306\307".
223 "\310\311\312\313\314\315\316\317".
224 "\320\321\322\323\324\325\326\327".
225 "\330\331\332\333\334\335\336\337".
226 "\340\341\342\343\344\345\346\347".
227 "\350\351\352\353\354\355\356\357".
228 "\360\361\362\363\364\365\366\367".
a2a7852b 229 "\370\371\372\373\374\375\376\377",
1fd97780 230 "????????????????????????????????????????".
231 "????????????????????????????????????????".
232 "????????????????????????????????????????".
233 "????????"));
a2a7852b 234
235}
236
237/*
238 * This is the same as ISO-646-NO and is used by some
239 * Microsoft programs when sending Norwegian characters
240 */
241function charset_decode_ns_4551_1 ($string) {
242 /*
243 * These characters are:
244 * Latin capital letter AE
245 * Latin capital letter O with stroke
246 * Latin capital letter A with ring above
247 * and the same as small letters
248 */
249 return strtr ($string, "[\\]{|}", "");
250}
251
6fbd125b 252
a2a7852b 253/*
254 * Set up the language to be output
255 * if $do_search is true, then scan the browser information
256 * for a possible language that we know
257 */
67a8c90a 258function set_up_language($sm_language, $do_search = false, $default = false) {
a2a7852b 259
260 static $SetupAlready = 0;
9eb0fbd4 261 global $use_gettext, $languages,
a2a7852b 262 $squirrelmail_language, $squirrelmail_default_language,
263 $sm_notAlias;
264
265 if ($SetupAlready) {
266 return;
267 }
a65846a7 268
5c920668 269 $SetupAlready = TRUE;
961ca3d8 270 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
a2a7852b 271
961ca3d8 272 if ($do_search && ! $sm_language && isset($accept_lang)) {
273 $sm_language = substr($accept_lang, 0, 2);
a2a7852b 274 }
66d7950f 275
67a8c90a 276 if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
a2a7852b 277 $squirrelmail_language = $squirrelmail_default_language;
66d7950f 278 $sm_language = $squirrelmail_default_language;
a2a7852b 279 }
280 $sm_notAlias = $sm_language;
3ec81e63 281
282 // Catching removed translation
283 // System reverts to English translation if user prefs contain translation
284 // that is not available in $languages array (admin removed directory
285 // with that translation)
286 if (!isset($languages[$sm_notAlias])) {
287 $sm_notAlias="en_US";
288 }
289
a2a7852b 290 while (isset($languages[$sm_notAlias]['ALIAS'])) {
291 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
292 }
293
88cb1b4d 294 if ( isset($sm_language) &&
5c920668 295 $use_gettext &&
296 $sm_language != '' &&
297 isset($languages[$sm_notAlias]['CHARSET']) ) {
a65846a7 298 bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
88cb1b4d 299 textdomain( 'squirrelmail' );
7928848f 300 if (function_exists('bind_textdomain_codeset')) {
301 bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
302 }
f2374580 303 if (isset($languages[$sm_notAlias]['LOCALE'])){
304 $longlocale=$languages[$sm_notAlias]['LOCALE'];
305 } else {
306 $longlocale=$sm_notAlias;
307 }
88cb1b4d 308 if ( !ini_get('safe_mode') &&
f2374580 309 getenv( 'LC_ALL' ) != $longlocale ) {
310 putenv( "LC_ALL=$longlocale" );
311 putenv( "LANG=$longlocale" );
312 putenv( "LANGUAGE=$longlocale" );
a2a7852b 313 }
f2374580 314 setlocale(LC_ALL, $longlocale);
315 $squirrelmail_language = $sm_notAlias;
538f1ab7 316 if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
b05c8961 317 header ('Content-Type: text/html; charset=EUC-JP');
318 if (!function_exists('mb_internal_encoding')) {
e842b215 319 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --enable-mbstring).");
320 }
321 if (function_exists('mb_language')) {
322 mb_language('Japanese');
b05c8961 323 }
324 mb_internal_encoding('EUC-JP');
325 mb_http_output('pass');
326 } else {
5c920668 327 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
a2a7852b 328 }
329}
b05c8961 330}
a2a7852b 331
332function set_my_charset(){
333
334 /*
335 * There can be a $default_charset setting in the
336 * config.php file, but the user may have a different language
337 * selected for a user interface. This function checks the
338 * language selected by the user and tags the outgoing messages
339 * with the appropriate charset corresponding to the language
340 * selection. This is "more right" (tm), than just stamping the
341 * message blindly with the system-wide $default_charset.
342 */
94965562 343 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
88cb1b4d 344
a2a7852b 345 $my_language = getPref($data_dir, $username, 'language');
5c920668 346 if (!$my_language) {
94965562 347 $my_language = $squirrelmail_default_language ;
5c920668 348 }
3ec81e63 349 // Catch removed translation
350 if (!isset($languages[$my_language])) {
351 $my_language="en_US";
352 }
a2a7852b 353 while (isset($languages[$my_language]['ALIAS'])) {
f7e8861e 354 $my_language = $languages[$my_language]['ALIAS'];
a2a7852b 355 }
5c920668 356 $my_charset = $languages[$my_language]['CHARSET'];
a2a7852b 357 if ($my_charset) {
358 $default_charset = $my_charset;
359 }
360}
361
a2a7852b 362/* ------------------------------ main --------------------------- */
363
5c920668 364global $squirrelmail_language, $languages, $use_gettext;
365
a2a7852b 366if (! isset($squirrelmail_language)) {
367 $squirrelmail_language = '';
368}
369
370/* This array specifies the available languages. */
5c920668 371
ddc315a7 372if ( file_exists( SM_PATH . 'locale/ca_ES') ) {
373 // The glibc locale is ca_ES.
374 $languages['ca_ES']['NAME'] = 'Catalan';
375 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
376 $languages['ca']['ALIAS'] = 'ca_ES';
377}
a2a7852b 378
ddc315a7 379if ( file_exists( SM_PATH . 'locale/cs_CZ') ) {
380 $languages['cs_CZ']['NAME'] = 'Czech';
9d62d800 381 $languages['cs_CZ']['ALTNAME'] = '&#268;e&scaron;tina';
ddc315a7 382 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
383 $languages['cs']['ALIAS'] = 'cs_CZ';
384}
5c920668 385
ddc315a7 386if ( file_exists( SM_PATH . 'locale/da_DK') ) {
387 // Danish locale is da_DK.
388 $languages['da_DK']['NAME'] = 'Danish';
9d62d800 389 $languages['da_DK']['ALTNAME'] = 'Dansk';
ddc315a7 390 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
391 $languages['da']['ALIAS'] = 'da_DK';
392}
5c920668 393
ddc315a7 394if ( file_exists( SM_PATH . 'locale/de_DE') ) {
9d62d800 395 $languages['de_DE']['NAME'] = 'German';
396 $languages['de_DE']['ALTNAME'] = 'Deutsch';
ddc315a7 397 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
398 $languages['de']['ALIAS'] = 'de_DE';
399}
a2a7852b 400
5c920668 401// There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
402// but who cares about !US, right? Right? :)
a2a7852b 403
ddc315a7 404if ( file_exists( SM_PATH . 'locale/el_GR') ) {
405 $languages['el_GR']['NAME'] = 'Greek';
9d62d800 406 $languages['el_GR']['ALTNAME'] = '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;';
ddc315a7 407 $languages['el_GR']['CHARSET'] = 'iso-8859-7';
408 $languages['el']['ALIAS'] = 'el_GR';
409}
3ab35042 410
5c920668 411$languages['en_US']['NAME'] = 'English';
412$languages['en_US']['CHARSET'] = 'iso-8859-1';
413$languages['en']['ALIAS'] = 'en_US';
a2a7852b 414
ddc315a7 415if ( file_exists( SM_PATH . 'locale/es_ES') ) {
416 $languages['es_ES']['NAME'] = 'Spanish';
9d62d800 417 $languages['es_ES']['ALTNAME'] = 'Espa&ntilde;ol';
ddc315a7 418 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
419 $languages['es']['ALIAS'] = 'es_ES';
420}
421if ( file_exists( SM_PATH . 'locale/et_EE') ) {
422 $languages['et_EE']['NAME'] = 'Estonian';
423 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
424 $languages['et']['ALIAS'] = 'et_EE';
425}
426if ( file_exists( SM_PATH . 'locale/fo_FO') ) {
427 $languages['fo_FO']['NAME'] = 'Faroese';
428 $languages['fo_FO']['CHARSET'] = 'iso-8859-1';
429 $languages['fo']['ALIAS'] = 'fo_FO';
430}
431if ( file_exists( SM_PATH . 'locale/fi_FI') ) {
432 $languages['fi_FI']['NAME'] = 'Finnish';
9d62d800 433 $languages['fi_FI']['ALTNAME'] = 'Suomi';
ddc315a7 434 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
435 $languages['fi']['ALIAS'] = 'fi_FI';
436}
437if ( file_exists( SM_PATH . 'locale/fr_FR') ) {
438 $languages['fr_FR']['NAME'] = 'French';
9d62d800 439 $languages['fr_FR']['ALTNAME'] = 'Fran&#231;ais';
ddc315a7 440 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
441 $languages['fr']['ALIAS'] = 'fr_FR';
442}
443if ( file_exists( SM_PATH . 'locale/hr_HR') ) {
444 $languages['hr_HR']['NAME'] = 'Croatian';
445 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
446 $languages['hr']['ALIAS'] = 'hr_HR';
447}
448if ( file_exists( SM_PATH . 'locale/hu_HU') ) {
449 $languages['hu_HU']['NAME'] = 'Hungarian';
9d62d800 450 $languages['hu_HU']['ALTNAME'] = 'Magyar';
ddc315a7 451 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
452 $languages['hu']['ALIAS'] = 'hu_HU';
453}
454if ( file_exists( SM_PATH . 'locale/id_ID') ) {
9d62d800 455 $languages['id_ID']['NAME'] = 'Indonesian';
456 $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
ddc315a7 457 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
458 $languages['id']['ALIAS'] = 'id_ID';
459}
460if ( file_exists( SM_PATH . 'locale/is_IS') ) {
461 $languages['is_IS']['NAME'] = 'Icelandic';
9d62d800 462 $languages['is_IS']['ALTNAME'] = '&Iacute;slenska';
ddc315a7 463 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
464 $languages['is']['ALIAS'] = 'is_IS';
465}
466if ( file_exists( SM_PATH . 'locale/it_IT') ) {
467 $languages['it_IT']['NAME'] = 'Italian';
468 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
469 $languages['it']['ALIAS'] = 'it_IT';
470}
471if ( file_exists( SM_PATH . 'locale/ja_JP') ) {
472 $languages['ja_JP']['NAME'] = 'Japanese';
9d62d800 473 $languages['ja_JP']['ALTNAME'] = '&#26085;&#26412;&#35486;';
ddc315a7 474 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
475 $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
476 $languages['ja']['ALIAS'] = 'ja_JP';
477}
478if ( file_exists( SM_PATH . 'locale/ko_KR') ) {
479 $languages['ko_KR']['NAME'] = 'Korean';
480 $languages['ko_KR']['CHARSET'] = 'euc-KR';
481 $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
482 $languages['ko']['ALIAS'] = 'ko_KR';
483}
484if ( file_exists( SM_PATH . 'locale/nl_NL') ) {
485 $languages['nl_NL']['NAME'] = 'Dutch';
9d62d800 486 $languages['nl_NL']['ALTNAME'] = 'Nederlands';
ddc315a7 487 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
488 $languages['nl']['ALIAS'] = 'nl_NL';
489}
060c9483 490if ( file_exists( SM_PATH . 'locale/ms_MY') ) {
9d62d800 491 $languages['ms_MY']['NAME'] = 'Malay';
492 $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
060c9483 493 $languages['ms_MY']['CHARSET'] = 'iso-8859-1';
494 $languages['my']['ALIAS'] = 'ms_MY';
495}
496
ddc315a7 497if ( file_exists( SM_PATH . 'locale/no_NO') ) {
498 $languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
9d62d800 499 $languages['no_NO']['ALTNAME'] = 'Norsk (Bokm&aring;l)';
ddc315a7 500 $languages['no_NO']['CHARSET'] = 'iso-8859-1';
501 $languages['no']['ALIAS'] = 'no_NO';
502}
503if ( file_exists( SM_PATH . 'locale/nn_NO') ) {
504 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
9d62d800 505 $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
ddc315a7 506 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
507}
508if ( file_exists( SM_PATH . 'locale/pl_PL') ) {
509 $languages['pl_PL']['NAME'] = 'Polish';
9d62d800 510 $languages['pl_PL']['ALTNAME'] = 'Polski';
ddc315a7 511 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
512 $languages['pl']['ALIAS'] = 'pl_PL';
513}
514if ( file_exists( SM_PATH . 'locale/pt_PT') ) {
515 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
516 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
517 $languages['pt']['ALIAS'] = 'pt_PT';
518}
519if ( file_exists( SM_PATH . 'locale/pt_BR') ) {
520 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
9d62d800 521 $languages['pt_BR']['ALTNAME'] = 'Portugu&ecirc;s do Brasil';
ddc315a7 522 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
523}
524if ( file_exists( SM_PATH . 'locale/ru_RU') ) {
525 $languages['ru_RU']['NAME'] = 'Russian';
9d62d800 526 $languages['ru_RU']['ALTNAME'] = '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;';
f96f799a 527 $languages['ru_RU']['CHARSET'] = 'utf-8';
528 $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
ddc315a7 529 $languages['ru']['ALIAS'] = 'ru_RU';
530}
531if ( file_exists( SM_PATH . 'locale/sr_YU') ) {
532 $languages['sr_YU']['NAME'] = 'Serbian';
9d62d800 533 $languages['sr_YU']['ALTNAME'] = 'Srpski';
ddc315a7 534 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
535 $languages['sr']['ALIAS'] = 'sr_YU';
536}
537if ( file_exists( SM_PATH . 'locale/sv_SE') ) {
538 $languages['sv_SE']['NAME'] = 'Swedish';
9d62d800 539 $languages['sv_SE']['ALTNAME'] = 'Svenska';
ddc315a7 540 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
541 $languages['sv']['ALIAS'] = 'sv_SE';
542}
543if ( file_exists( SM_PATH . 'locale/tr_TR') ) {
544 $languages['tr_TR']['NAME'] = 'Turkish';
545 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
546 $languages['tr']['ALIAS'] = 'tr_TR';
547}
548if ( file_exists( SM_PATH . 'locale/zh_TW') ) {
549 $languages['zh_TW']['NAME'] = 'Chinese Trad';
550 $languages['zh_TW']['CHARSET'] = 'big5';
551 $languages['tw']['ALIAS'] = 'zh_TW';
552}
553if ( file_exists( SM_PATH . 'locale/zh_CN') ) {
554 $languages['zh_CN']['NAME'] = 'Chinese Simp';
555 $languages['zh_CN']['CHARSET'] = 'gb2312';
556 $languages['cn']['ALIAS'] = 'zh_CN';
557}
558if ( file_exists( SM_PATH . 'locale/sk_SK') ) {
559 $languages['sk_SK']['NAME'] = 'Slovak';
560 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
561 $languages['sk']['ALIAS'] = 'sk_SK';
562}
563if ( file_exists( SM_PATH . 'locale/ro_RO') ) {
564 $languages['ro_RO']['NAME'] = 'Romanian';
9d62d800 565 $languages['ro_RO']['ALTNAME'] = 'Rom&acirc;n&#259;';
ddc315a7 566 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
567 $languages['ro']['ALIAS'] = 'ro_RO';
568}
569if ( file_exists( SM_PATH . 'locale/th_TH') ) {
570 $languages['th_TH']['NAME'] = 'Thai';
571 $languages['th_TH']['CHARSET'] = 'tis-620';
572 $languages['th']['ALIAS'] = 'th_TH';
573}
574if ( file_exists( SM_PATH . 'locale/lt_LT') ) {
575 $languages['lt_LT']['NAME'] = 'Lithuanian';
9d62d800 576 $languages['lt_LT']['ALTNAME'] = 'Lietuvi&#371;';
f67cfab7 577 $languages['lt_LT']['CHARSET'] = 'utf-8';
578 $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
ddc315a7 579 $languages['lt']['ALIAS'] = 'lt_LT';
580}
581if ( file_exists( SM_PATH . 'locale/sl_SI') ) {
582 $languages['sl_SI']['NAME'] = 'Slovenian';
9d62d800 583 $languages['sl_SI']['ALTNAME'] = 'Sloven&scaron;&#269;ina';
ddc315a7 584 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
585 $languages['sl']['ALIAS'] = 'sl_SI';
586}
587if ( file_exists( SM_PATH . 'locale/bg_BG') ) {
588 $languages['bg_BG']['NAME'] = 'Bulgarian';
9d62d800 589 $languages['bg_BG']['ALTNAME'] = '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;';
ddc315a7 590 $languages['bg_BG']['CHARSET'] = 'windows-1251';
591 $languages['bg']['ALIAS'] = 'bg_BG';
592}
87c6b544 593/*
ddc315a7 594if ( file_exists( SM_PATH . 'locale/uk_UA') ) {
595 $languages['uk_UA']['NAME'] = 'Ukrainian';
596 $languages['uk_UA']['CHARSET'] = 'koi8-u';
597 $languages['uk']['ALIAS'] = 'uk_UA';
598}
87c6b544 599*/
ddc315a7 600if ( file_exists( SM_PATH . 'locale/cy_GB') ) {
601 $languages['cy_GB']['NAME'] = 'Welsh';
9d62d800 602 $languages['cy_GB']['ALTNAME'] = 'Cymraeg';
ddc315a7 603 $languages['cy_GB']['CHARSET'] = 'iso-8859-1';
604 $languages['cy']['ALIAS'] = 'cy_GB';
605}
87c6b544 606/*
ddc315a7 607if ( file_exists( SM_PATH . 'locale/vi_VN') ) {
608 $languages['vi_VN']['NAME'] = 'Vietnamese';
609 $languages['vi_VN']['CHARSET'] = 'utf-8';
610 $languages['vi']['ALIAS'] = 'vi_VN';
611}
87c6b544 612*/
d3b57948 613// Right to left languages
ddc315a7 614if ( file_exists( SM_PATH . 'locale/ar') ) {
615 $languages['ar']['NAME'] = 'Arabic';
616 $languages['ar']['CHARSET'] = 'windows-1256';
617 $languages['ar']['DIR'] = 'rtl';
618}
619if ( file_exists( SM_PATH . 'locale/he_IL') ) {
620 $languages['he_IL']['NAME'] = 'Hebrew';
621 $languages['he_IL']['CHARSET'] = 'windows-1255';
622 $languages['he_IL']['DIR'] = 'rtl';
623 $languages['he']['ALIAS'] = 'he_IL';
624}
d3b57948 625
5c920668 626/* Detect whether gettext is installed. */
a2a7852b 627$gettext_flags = 0;
628if (function_exists('_')) {
629 $gettext_flags += 1;
630}
631if (function_exists('bindtextdomain')) {
632 $gettext_flags += 2;
633}
634if (function_exists('textdomain')) {
635 $gettext_flags += 4;
636}
637
5c920668 638/* If gettext is fully loaded, cool */
a2a7852b 639if ($gettext_flags == 7) {
640 $use_gettext = true;
641}
5c920668 642/* If we can fake gettext, try that */
a2a7852b 643elseif ($gettext_flags == 0) {
644 $use_gettext = true;
e7ab8c9d 645 include_once(SM_PATH . 'functions/gettext.php');
a2a7852b 646} else {
5c920668 647 /* Uh-ho. A weird install */
a2a7852b 648 if (! $gettext_flags & 1) {
649 function _($str) {
650 return $str;
651 }
652 }
653 if (! $gettext_flags & 2) {
654 function bindtextdomain() {
655 return;
656 }
657 }
658 if (! $gettext_flags & 4) {
659 function textdomain() {
660 return;
661 }
662 }
663}
664
1d33e35e 665
666/*
667 * Japanese charset extra function
668 *
669 */
670function japanese_charset_xtra() {
671 $ret = func_get_arg(1); /* default return value */
672 if (function_exists('mb_detect_encoding')) {
673 switch (func_get_arg(0)) { /* action */
674 case 'decode':
e842b215 675 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 676 if ($detect_encoding == 'JIS' ||
677 $detect_encoding == 'EUC-JP' ||
e842b215 678 $detect_encoding == 'SJIS' ||
679 $detect_encoding == 'UTF-8') {
1d33e35e 680
e842b215 681 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
1d33e35e 682 }
683 break;
684 case 'encode':
e842b215 685 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 686 if ($detect_encoding == 'JIS' ||
687 $detect_encoding == 'EUC-JP' ||
e842b215 688 $detect_encoding == 'SJIS' ||
689 $detect_encoding == 'UTF-8') {
1d33e35e 690
e842b215 691 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
1d33e35e 692 }
693 break;
694 case 'strimwidth':
695 $width = func_get_arg(2);
696 $ret = mb_strimwidth($ret, 0, $width, '...');
697 break;
698 case 'encodeheader':
8ba05cbe 699 $result = '';
700 if (strlen($ret) > 0) {
701 $tmpstr = mb_substr($ret, 0, 1);
702 $prevcsize = strlen($tmpstr);
703 for ($i = 1; $i < mb_strlen($ret); $i++) {
704 $tmp = mb_substr($ret, $i, 1);
705 if (strlen($tmp) == $prevcsize) {
706 $tmpstr .= $tmp;
707 } else {
708 if ($prevcsize == 1) {
709 $result .= $tmpstr;
710 } else {
e842b215 711 $result .= str_replace(' ', '',
712 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 713 }
714 $tmpstr = $tmp;
715 $prevcsize = strlen($tmp);
716 }
717 }
718 if (strlen($tmpstr)) {
719 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
720 $result .= $tmpstr;
721 else
e842b215 722 $result .= str_replace(' ', '',
723 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 724 }
725 }
726 $ret = $result;
1d33e35e 727 break;
728 case 'decodeheader':
729 $ret = str_replace("\t", "", $ret);
730 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
e842b215 731 $ret = @mb_decode_mimeheader($ret);
732 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1d33e35e 733 break;
734 case 'downloadfilename':
735 $useragent = func_get_arg(2);
736 if (strstr($useragent, 'Windows') !== false ||
737 strstr($useragent, 'Mac_') !== false) {
738 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
739 } else {
740 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
741}
742 break;
e842b215 743 case 'wordwrap':
744 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
745 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
746 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
747 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
748 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
749 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
750 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
751 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
752 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
753 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
754 $wrap = func_get_arg(2);
755
756 if (strlen($ret) >= $wrap &&
757 substr($ret, 0, 1) != '>' &&
758 strpos($ret, 'http://') === FALSE &&
759 strpos($ret, 'https://') === FALSE &&
760 strpos($ret, 'ftp://') === FALSE) {
761
762 $ret = mb_convert_kana($ret, "KV");
763
764 $line_new = '';
765 $ptr = 0;
766
767 while ($ptr < strlen($ret) - 1) {
768 $l = mb_strcut($ret, $ptr, $wrap);
769 $ptr += strlen($l);
770 $tmp = $l;
771
772 $l = mb_strcut($ret, $ptr, 2);
773 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
774 $tmp .= $l;
775 $ptr += strlen($l);
776 $l = mb_strcut($ret, $ptr, 1);
777 }
778 $line_new .= $tmp;
779 if ($ptr < strlen($ret) - 1)
780 $line_new .= "\n";
781 }
782 $ret = $line_new;
783 }
784 break;
785 case 'utf7-imap_encode':
786 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
787 break;
788 case 'utf7-imap_decode':
789 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
790 break;
1d33e35e 791 }
792 }
793 return $ret;
794}
795
796
797/*
798 * Korean charset extra function
799 * Hangul(Korean Character) Attached File Name Fix.
800 */
801function korean_charset_xtra() {
802
803 $ret = func_get_arg(1); /* default return value */
804 if (func_get_arg(0) == 'downloadfilename') { /* action */
805 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
806 for ($i=0;$i<strlen($ret);$i++) {
807 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
808 $i++;
809 continue;
810 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
811 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
812 ($ret[$i] == '.') || ($ret[$i] == '-')) {
813 continue;
814 } else {
815 $ret[$i] = '_';
816 }
817 }
818
819 }
820
821 return $ret;
822}
823
9af9c0a2 824/*
825 * This function can be used to replace non-braking space symbols
826 * that are inserted in forms by some browsers instead of normal
827 * space symbol.
828 */
829function cleanup_nbsp($string,$charset) {
830
831 // reduce number of case statements
832 if (stristr('iso-8859-',substr($charset,0,9))){
833 $output_charset="iso-8859-x";
834 }
835 if (stristr('windows-125',substr($charset,0,11))){
836 $output_charset="cp125x";
837 }
838 if (stristr('koi8',substr($charset,0,4))){
839 $output_charset="koi8-x";
840 }
841 if (! isset($output_charset)){
842 $output_charset=strtolower($charset);
843 }
844
845// where is non-braking space symbol
846switch($output_charset):
847 case "iso-8859-x":
97b9c02f 848 case "cp125x":
849 case "iso-2022-jp":
9af9c0a2 850 $nbsp="\xA0";
851 break;
9af9c0a2 852 case "koi8-x":
853 $nbsp="\x9A";
854 break;
855 case "utf-8":
856 $nbsp="\xC2\xA0";
857 break;
9af9c0a2 858 default:
859 // don't change string if charset is unmatched
860 return $string;
861endswitch;
862
863// return space instead of non-braking space.
864 return str_replace($nbsp,' ',$string);
865}
4e519821 866
867function is_conversion_safe($input_charset) {
868 global $languages, $sm_notAlias, $default_charset;
869
870 // convert to lower case
871 $input_charset = strtolower($input_charset);
872
873 // Is user's locale Unicode based ?
874 if ( $default_charset == "utf-8" ) {
875 return true;
876 }
877
878 // Charsets that are similar
879switch ($default_charset):
880case "windows-1251":
881 if ( $input_charset == "iso-8859-5" ||
882 $input_charset == "koi8-r" ||
883 $input_charset == "koi8-u" ) {
884 return true;
885 } else {
886 return false;
887 }
888case "windows-1257":
889 if ( $input_charset == "iso-8859-13" ||
890 $input_charset == "iso-8859-4" ) {
891 return true;
892 } else {
893 return false;
894 }
895case "iso-8859-4":
896 if ( $input_charset == "iso-8859-13" ||
897 $input_charset == "windows-1257" ) {
898 return true;
899 } else {
900 return false;
901 }
902case "iso-8859-5":
903 if ( $input_charset == "windows-1251" ||
904 $input_charset == "koi8-r" ||
905 $input_charset == "koi8-u" ) {
906 return true;
907 } else {
908 return false;
909 }
910case "iso-8859-13":
911 if ( $input_charset == "iso-8859-4" ||
912 $input_charset == "windows-1257" ) {
913 return true;
914 } else {
915 return false;
916 }
917case "koi8-r":
918 if ( $input_charset == "windows-1251" ||
919 $input_charset == "iso-8859-5" ||
920 $input_charset == "koi8-u" ) {
921 return true;
922 } else {
923 return false;
924 }
925case "koi8-u":
926 if ( $input_charset == "windows-1251" ||
927 $input_charset == "iso-8859-5" ||
928 $input_charset == "koi8-r" ) {
929 return true;
930 } else {
931 return false;
932 }
933default:
934 return false;
935endswitch;
936}
060c9483 937?>