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