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