Today Cyrus 2.2.2-BETA with SASL Initial Client response was released so it
[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);
96d985e5 206 } else if ($charset == 'utf-8' && $squirrelmail_language != 'ja_JP') {
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. */
a8fa8e33 371$languages['bg_BG']['NAME'] = 'Bulgarian';
372$languages['bg_BG']['ALTNAME'] = '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;';
373$languages['bg_BG']['CHARSET'] = 'windows-1251';
374$languages['bg']['ALIAS'] = 'bg_BG';
375
376$languages['ca_ES']['NAME'] = 'Catalan';
377$languages['ca_ES']['CHARSET'] = 'iso-8859-1';
378$languages['ca']['ALIAS'] = 'ca_ES';
379
380$languages['cs_CZ']['NAME'] = 'Czech';
381$languages['cs_CZ']['ALTNAME'] = '&#268;e&scaron;tina';
382$languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
383$languages['cs']['ALIAS'] = 'cs_CZ';
384
385$languages['cy_GB']['NAME'] = 'Welsh';
386$languages['cy_GB']['ALTNAME'] = 'Cymraeg';
387$languages['cy_GB']['CHARSET'] = 'iso-8859-1';
388$languages['cy']['ALIAS'] = 'cy_GB';
389
390// Danish locale is da_DK.
391$languages['da_DK']['NAME'] = 'Danish';
392$languages['da_DK']['ALTNAME'] = 'Dansk';
393$languages['da_DK']['CHARSET'] = 'iso-8859-1';
394$languages['da']['ALIAS'] = 'da_DK';
395
396$languages['de_DE']['NAME'] = 'German';
397$languages['de_DE']['ALTNAME'] = 'Deutsch';
398$languages['de_DE']['CHARSET'] = 'iso-8859-1';
399$languages['de']['ALIAS'] = 'de_DE';
400
401$languages['el_GR']['NAME'] = 'Greek';
402$languages['el_GR']['ALTNAME'] = '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;';
403$languages['el_GR']['CHARSET'] = 'iso-8859-7';
404$languages['el']['ALIAS'] = 'el_GR';
a2a7852b 405
5c920668 406// There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
407// but who cares about !US, right? Right? :)
5c920668 408$languages['en_US']['NAME'] = 'English';
409$languages['en_US']['CHARSET'] = 'iso-8859-1';
410$languages['en']['ALIAS'] = 'en_US';
a2a7852b 411
a8fa8e33 412$languages['es_ES']['NAME'] = 'Spanish';
413$languages['es_ES']['ALTNAME'] = 'Espa&ntilde;ol';
414$languages['es_ES']['CHARSET'] = 'iso-8859-1';
415$languages['es']['ALIAS'] = 'es_ES';
416
417$languages['et_EE']['NAME'] = 'Estonian';
418$languages['et_EE']['CHARSET'] = 'iso-8859-15';
419$languages['et']['ALIAS'] = 'et_EE';
420
421$languages['fo_FO']['NAME'] = 'Faroese';
422$languages['fo_FO']['CHARSET'] = 'iso-8859-1';
423$languages['fo']['ALIAS'] = 'fo_FO';
424
425$languages['fi_FI']['NAME'] = 'Finnish';
426$languages['fi_FI']['ALTNAME'] = 'Suomi';
427$languages['fi_FI']['CHARSET'] = 'iso-8859-1';
428$languages['fi']['ALIAS'] = 'fi_FI';
429
430$languages['fr_FR']['NAME'] = 'French';
431$languages['fr_FR']['ALTNAME'] = 'Fran&#231;ais';
432$languages['fr_FR']['CHARSET'] = 'iso-8859-1';
433$languages['fr']['ALIAS'] = 'fr_FR';
434
435$languages['hr_HR']['NAME'] = 'Croatian';
436$languages['hr_HR']['CHARSET'] = 'iso-8859-2';
437$languages['hr']['ALIAS'] = 'hr_HR';
438
439$languages['hu_HU']['NAME'] = 'Hungarian';
440$languages['hu_HU']['ALTNAME'] = 'Magyar';
441$languages['hu_HU']['CHARSET'] = 'iso-8859-2';
442$languages['hu']['ALIAS'] = 'hu_HU';
443
444$languages['id_ID']['NAME'] = 'Indonesian';
445$languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
446$languages['id_ID']['CHARSET'] = 'iso-8859-1';
447$languages['id']['ALIAS'] = 'id_ID';
448
449$languages['is_IS']['NAME'] = 'Icelandic';
450$languages['is_IS']['ALTNAME'] = '&Iacute;slenska';
451$languages['is_IS']['CHARSET'] = 'iso-8859-1';
452$languages['is']['ALIAS'] = 'is_IS';
453
454$languages['it_IT']['NAME'] = 'Italian';
455$languages['it_IT']['CHARSET'] = 'iso-8859-1';
456$languages['it']['ALIAS'] = 'it_IT';
457
458$languages['ja_JP']['NAME'] = 'Japanese';
459$languages['ja_JP']['ALTNAME'] = '&#26085;&#26412;&#35486;';
460$languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
461$languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
462$languages['ja']['ALIAS'] = 'ja_JP';
463
464$languages['ko_KR']['NAME'] = 'Korean';
465$languages['ko_KR']['CHARSET'] = 'euc-KR';
466$languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
467$languages['ko']['ALIAS'] = 'ko_KR';
468
469$languages['lt_LT']['NAME'] = 'Lithuanian';
470$languages['lt_LT']['ALTNAME'] = 'Lietuvi&#371;';
471$languages['lt_LT']['CHARSET'] = 'utf-8';
472$languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
473$languages['lt']['ALIAS'] = 'lt_LT';
474
475$languages['nl_NL']['NAME'] = 'Dutch';
476$languages['nl_NL']['ALTNAME'] = 'Nederlands';
477$languages['nl_NL']['CHARSET'] = 'iso-8859-1';
478$languages['nl']['ALIAS'] = 'nl_NL';
479
480$languages['ms_MY']['NAME'] = 'Malay';
481$languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
482$languages['ms_MY']['CHARSET'] = 'iso-8859-1';
483$languages['my']['ALIAS'] = 'ms_MY';
484
485$languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
486$languages['no_NO']['ALTNAME'] = 'Norsk (Bokm&aring;l)';
487$languages['no_NO']['CHARSET'] = 'iso-8859-1';
488$languages['no']['ALIAS'] = 'no_NO';
489
490$languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
491$languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
492$languages['nn_NO']['CHARSET'] = 'iso-8859-1';
493
494$languages['pl_PL']['NAME'] = 'Polish';
495$languages['pl_PL']['ALTNAME'] = 'Polski';
496$languages['pl_PL']['CHARSET'] = 'iso-8859-2';
497$languages['pl']['ALIAS'] = 'pl_PL';
498
499$languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
500$languages['pt_PT']['CHARSET'] = 'iso-8859-1';
501$languages['pt']['ALIAS'] = 'pt_PT';
502
503$languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
504$languages['pt_BR']['ALTNAME'] = 'Portugu&ecirc;s do Brasil';
505$languages['pt_BR']['CHARSET'] = 'iso-8859-1';
506
507$languages['ro_RO']['NAME'] = 'Romanian';
508$languages['ro_RO']['ALTNAME'] = 'Rom&acirc;n&#259;';
509$languages['ro_RO']['CHARSET'] = 'iso-8859-2';
510$languages['ro']['ALIAS'] = 'ro_RO';
511
512$languages['ru_RU']['NAME'] = 'Russian';
513$languages['ru_RU']['ALTNAME'] = '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;';
514$languages['ru_RU']['CHARSET'] = 'utf-8';
515$languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
516$languages['ru']['ALIAS'] = 'ru_RU';
517
518$languages['sk_SK']['NAME'] = 'Slovak';
519$languages['sk_SK']['CHARSET'] = 'iso-8859-2';
520$languages['sk']['ALIAS'] = 'sk_SK';
521
522$languages['sl_SI']['NAME'] = 'Slovenian';
523$languages['sl_SI']['ALTNAME'] = 'Sloven&scaron;&#269;ina';
524$languages['sl_SI']['CHARSET'] = 'iso-8859-2';
525$languages['sl']['ALIAS'] = 'sl_SI';
526
527$languages['sr_YU']['NAME'] = 'Serbian';
528$languages['sr_YU']['ALTNAME'] = 'Srpski';
529$languages['sr_YU']['CHARSET'] = 'iso-8859-2';
530$languages['sr']['ALIAS'] = 'sr_YU';
531
532$languages['sv_SE']['NAME'] = 'Swedish';
533$languages['sv_SE']['ALTNAME'] = 'Svenska';
534$languages['sv_SE']['CHARSET'] = 'iso-8859-1';
535$languages['sv']['ALIAS'] = 'sv_SE';
536
537$languages['th_TH']['NAME'] = 'Thai';
538$languages['th_TH']['CHARSET'] = 'tis-620';
539$languages['th']['ALIAS'] = 'th_TH';
540
541$languages['tr_TR']['NAME'] = 'Turkish';
542$languages['tr_TR']['CHARSET'] = 'iso-8859-9';
543$languages['tr']['ALIAS'] = 'tr_TR';
544
545$languages['zh_TW']['NAME'] = 'Chinese Trad';
546$languages['zh_TW']['CHARSET'] = 'big5';
547$languages['tw']['ALIAS'] = 'zh_TW';
548
549$languages['zh_CN']['NAME'] = 'Chinese Simp';
550$languages['zh_CN']['CHARSET'] = 'gb2312';
551$languages['cn']['ALIAS'] = 'zh_CN';
060c9483 552
87c6b544 553/*
a8fa8e33 554$languages['uk_UA']['NAME'] = 'Ukrainian';
555$languages['uk_UA']['CHARSET'] = 'koi8-u';
556$languages['uk']['ALIAS'] = 'uk_UA';
87c6b544 557*/
87c6b544 558/*
ddc315a7 559if ( file_exists( SM_PATH . 'locale/vi_VN') ) {
560 $languages['vi_VN']['NAME'] = 'Vietnamese';
561 $languages['vi_VN']['CHARSET'] = 'utf-8';
562 $languages['vi']['ALIAS'] = 'vi_VN';
563}
87c6b544 564*/
a8fa8e33 565
d3b57948 566// Right to left languages
a8fa8e33 567$languages['ar']['NAME'] = 'Arabic';
568$languages['ar']['CHARSET'] = 'windows-1256';
569$languages['ar']['DIR'] = 'rtl';
570
571$languages['he_IL']['NAME'] = 'Hebrew';
572$languages['he_IL']['CHARSET'] = 'windows-1255';
573$languages['he_IL']['DIR'] = 'rtl';
574$languages['he']['ALIAS'] = 'he_IL';
d3b57948 575
5c920668 576/* Detect whether gettext is installed. */
a2a7852b 577$gettext_flags = 0;
578if (function_exists('_')) {
579 $gettext_flags += 1;
580}
581if (function_exists('bindtextdomain')) {
582 $gettext_flags += 2;
583}
584if (function_exists('textdomain')) {
585 $gettext_flags += 4;
586}
587
5c920668 588/* If gettext is fully loaded, cool */
a2a7852b 589if ($gettext_flags == 7) {
590 $use_gettext = true;
591}
5c920668 592/* If we can fake gettext, try that */
a2a7852b 593elseif ($gettext_flags == 0) {
594 $use_gettext = true;
e7ab8c9d 595 include_once(SM_PATH . 'functions/gettext.php');
a2a7852b 596} else {
5c920668 597 /* Uh-ho. A weird install */
a2a7852b 598 if (! $gettext_flags & 1) {
599 function _($str) {
600 return $str;
601 }
602 }
603 if (! $gettext_flags & 2) {
604 function bindtextdomain() {
605 return;
606 }
607 }
608 if (! $gettext_flags & 4) {
609 function textdomain() {
610 return;
611 }
612 }
613}
614
1d33e35e 615
616/*
617 * Japanese charset extra function
618 *
619 */
620function japanese_charset_xtra() {
621 $ret = func_get_arg(1); /* default return value */
622 if (function_exists('mb_detect_encoding')) {
623 switch (func_get_arg(0)) { /* action */
624 case 'decode':
e842b215 625 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 626 if ($detect_encoding == 'JIS' ||
627 $detect_encoding == 'EUC-JP' ||
e842b215 628 $detect_encoding == 'SJIS' ||
629 $detect_encoding == 'UTF-8') {
1d33e35e 630
e842b215 631 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
1d33e35e 632 }
633 break;
634 case 'encode':
e842b215 635 $detect_encoding = @mb_detect_encoding($ret);
1d33e35e 636 if ($detect_encoding == 'JIS' ||
637 $detect_encoding == 'EUC-JP' ||
e842b215 638 $detect_encoding == 'SJIS' ||
639 $detect_encoding == 'UTF-8') {
1d33e35e 640
e842b215 641 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
1d33e35e 642 }
643 break;
644 case 'strimwidth':
645 $width = func_get_arg(2);
646 $ret = mb_strimwidth($ret, 0, $width, '...');
647 break;
648 case 'encodeheader':
8ba05cbe 649 $result = '';
650 if (strlen($ret) > 0) {
651 $tmpstr = mb_substr($ret, 0, 1);
652 $prevcsize = strlen($tmpstr);
653 for ($i = 1; $i < mb_strlen($ret); $i++) {
654 $tmp = mb_substr($ret, $i, 1);
655 if (strlen($tmp) == $prevcsize) {
656 $tmpstr .= $tmp;
657 } else {
658 if ($prevcsize == 1) {
659 $result .= $tmpstr;
660 } else {
e842b215 661 $result .= str_replace(' ', '',
662 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 663 }
664 $tmpstr = $tmp;
665 $prevcsize = strlen($tmp);
666 }
667 }
668 if (strlen($tmpstr)) {
669 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
670 $result .= $tmpstr;
671 else
e842b215 672 $result .= str_replace(' ', '',
673 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
8ba05cbe 674 }
675 }
676 $ret = $result;
1d33e35e 677 break;
678 case 'decodeheader':
679 $ret = str_replace("\t", "", $ret);
680 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
e842b215 681 $ret = @mb_decode_mimeheader($ret);
682 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1d33e35e 683 break;
684 case 'downloadfilename':
685 $useragent = func_get_arg(2);
686 if (strstr($useragent, 'Windows') !== false ||
687 strstr($useragent, 'Mac_') !== false) {
688 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
689 } else {
690 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
691}
692 break;
e842b215 693 case 'wordwrap':
694 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
695 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
696 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
697 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
698 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
699 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
700 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
701 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
702 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
703 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
704 $wrap = func_get_arg(2);
705
706 if (strlen($ret) >= $wrap &&
707 substr($ret, 0, 1) != '>' &&
708 strpos($ret, 'http://') === FALSE &&
709 strpos($ret, 'https://') === FALSE &&
710 strpos($ret, 'ftp://') === FALSE) {
711
712 $ret = mb_convert_kana($ret, "KV");
713
714 $line_new = '';
715 $ptr = 0;
716
717 while ($ptr < strlen($ret) - 1) {
718 $l = mb_strcut($ret, $ptr, $wrap);
719 $ptr += strlen($l);
720 $tmp = $l;
721
722 $l = mb_strcut($ret, $ptr, 2);
723 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
724 $tmp .= $l;
725 $ptr += strlen($l);
726 $l = mb_strcut($ret, $ptr, 1);
727 }
728 $line_new .= $tmp;
729 if ($ptr < strlen($ret) - 1)
730 $line_new .= "\n";
731 }
732 $ret = $line_new;
733 }
734 break;
735 case 'utf7-imap_encode':
736 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
737 break;
738 case 'utf7-imap_decode':
739 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
740 break;
1d33e35e 741 }
742 }
743 return $ret;
744}
745
746
747/*
748 * Korean charset extra function
749 * Hangul(Korean Character) Attached File Name Fix.
750 */
751function korean_charset_xtra() {
752
753 $ret = func_get_arg(1); /* default return value */
754 if (func_get_arg(0) == 'downloadfilename') { /* action */
755 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
756 for ($i=0;$i<strlen($ret);$i++) {
757 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
758 $i++;
759 continue;
760 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
761 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
762 ($ret[$i] == '.') || ($ret[$i] == '-')) {
763 continue;
764 } else {
765 $ret[$i] = '_';
766 }
767 }
768
769 }
770
771 return $ret;
772}
773
9af9c0a2 774/*
775 * This function can be used to replace non-braking space symbols
776 * that are inserted in forms by some browsers instead of normal
777 * space symbol.
778 */
779function cleanup_nbsp($string,$charset) {
780
781 // reduce number of case statements
782 if (stristr('iso-8859-',substr($charset,0,9))){
783 $output_charset="iso-8859-x";
784 }
785 if (stristr('windows-125',substr($charset,0,11))){
786 $output_charset="cp125x";
787 }
788 if (stristr('koi8',substr($charset,0,4))){
789 $output_charset="koi8-x";
790 }
791 if (! isset($output_charset)){
792 $output_charset=strtolower($charset);
793 }
794
795// where is non-braking space symbol
796switch($output_charset):
797 case "iso-8859-x":
97b9c02f 798 case "cp125x":
799 case "iso-2022-jp":
9af9c0a2 800 $nbsp="\xA0";
801 break;
9af9c0a2 802 case "koi8-x":
803 $nbsp="\x9A";
804 break;
805 case "utf-8":
806 $nbsp="\xC2\xA0";
807 break;
9af9c0a2 808 default:
809 // don't change string if charset is unmatched
810 return $string;
811endswitch;
812
813// return space instead of non-braking space.
814 return str_replace($nbsp,' ',$string);
815}
4e519821 816
817function is_conversion_safe($input_charset) {
818 global $languages, $sm_notAlias, $default_charset;
819
820 // convert to lower case
821 $input_charset = strtolower($input_charset);
822
823 // Is user's locale Unicode based ?
824 if ( $default_charset == "utf-8" ) {
825 return true;
826 }
827
828 // Charsets that are similar
829switch ($default_charset):
830case "windows-1251":
831 if ( $input_charset == "iso-8859-5" ||
832 $input_charset == "koi8-r" ||
833 $input_charset == "koi8-u" ) {
834 return true;
835 } else {
836 return false;
837 }
838case "windows-1257":
839 if ( $input_charset == "iso-8859-13" ||
840 $input_charset == "iso-8859-4" ) {
841 return true;
842 } else {
843 return false;
844 }
845case "iso-8859-4":
846 if ( $input_charset == "iso-8859-13" ||
847 $input_charset == "windows-1257" ) {
848 return true;
849 } else {
850 return false;
851 }
852case "iso-8859-5":
853 if ( $input_charset == "windows-1251" ||
854 $input_charset == "koi8-r" ||
855 $input_charset == "koi8-u" ) {
856 return true;
857 } else {
858 return false;
859 }
860case "iso-8859-13":
861 if ( $input_charset == "iso-8859-4" ||
862 $input_charset == "windows-1257" ) {
863 return true;
864 } else {
865 return false;
866 }
867case "koi8-r":
868 if ( $input_charset == "windows-1251" ||
869 $input_charset == "iso-8859-5" ||
870 $input_charset == "koi8-u" ) {
871 return true;
872 } else {
873 return false;
874 }
875case "koi8-u":
876 if ( $input_charset == "windows-1251" ||
877 $input_charset == "iso-8859-5" ||
878 $input_charset == "koi8-r" ) {
879 return true;
880 } else {
881 return false;
882 }
883default:
884 return false;
885endswitch;
886}
060c9483 887?>