Use C character conversion rules if Turkish translation is used. Breaks
[squirrelmail.git] / functions / i18n.php
1 <?php
2
3 /**
4 * SquirrelMail internationalization functions
5 *
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
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 * @version $Id$
16 * @package squirrelmail
17 * @subpackage i18n
18 */
19
20 /** Everything uses global.php... */
21 require_once(SM_PATH . 'functions/global.php');
22
23 /**
24 * Converts string from given charset to charset, that can be displayed by user translation.
25 *
26 * Function by default returns html encoded strings, if translation uses different encoding.
27 * If Japanese translation is used - function returns string converted to euc-jp
28 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
29 * If $charset is not supported - function returns unconverted string.
30 *
31 * sanitizing of html tags is also done by this function.
32 *
33 * @param string $charset
34 * @param string $string Text to be decoded
35 * @return string decoded string
36 */
37 function charset_decode ($charset, $string) {
38 global $languages, $squirrelmail_language, $default_charset;
39 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
40
41 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
42 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
43 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
44 }
45
46 $charset = strtolower($charset);
47
48 set_my_charset();
49
50 // Variables that allow to use functions without function_exist() calls
51 if (! isset($use_php_recode) || $use_php_recode=="" ) {
52 $use_php_recode=false; }
53 if (! isset($use_php_iconv) || $use_php_iconv=="" ) {
54 $use_php_iconv=false; }
55
56 // Don't do conversion if charset is the same.
57 if ( $charset == strtolower($default_charset) )
58 return htmlspecialchars($string);
59
60 // catch iso-8859-8-i thing
61 if ( $charset == "iso-8859-8-i" )
62 $charset = "iso-8859-8";
63
64 /*
65 * Recode converts html special characters automatically if you use
66 * 'charset..html' decoding. There is no documented way to put -d option
67 * into php recode function call.
68 */
69 if ( $use_php_recode ) {
70 if ( $default_charset == "utf-8" ) {
71 // other charsets can be converted to utf-8 without loss.
72 // and output string is smaller
73 $string = recode_string($charset . "..utf-8",$string);
74 return htmlspecialchars($string);
75 } else {
76 $string = recode_string($charset . "..html",$string);
77 // recode does not convert single quote, htmlspecialchars does.
78 $string = str_replace("'", '&#039;', $string);
79 return $string;
80 }
81 }
82
83 // iconv functions does not have html target and can be used only with utf-8
84 if ( $use_php_iconv && $default_charset=='utf-8') {
85 $string = iconv($charset,$default_charset,$string);
86 return htmlspecialchars($string);
87 }
88
89 // If we don't use recode and iconv, we'll do it old way.
90
91 /* All HTML special characters are 7 bit and can be replaced first */
92
93 $string = htmlspecialchars ($string);
94
95 /* controls cpu and memory intensive decoding cycles */
96 if (! isset($aggressive_decoding) || $aggressive_decoding=="" ) {
97 $aggressive_decoding=false; }
98
99 $decode=fixcharset($charset);
100 $decodefile=SM_PATH . 'functions/decode/' . $decode . '.php';
101 if (file_exists($decodefile)) {
102 include_once($decodefile);
103 $ret = call_user_func('charset_decode_'.$decode, $string);
104 } else {
105 $ret = $string;
106 }
107 return( $ret );
108 }
109
110 /**
111 * Converts html string to given charset
112 * @param string $string
113 * @param string $charset
114 * @param boolean $htmlencode keep htmlspecialchars encoding
115 * @param string
116 */
117 function charset_encode($string,$charset,$htmlencode=true) {
118 global $default_charset;
119
120 // Undo html special chars
121 if (! $htmlencode ) {
122 $string = str_replace(array('&amp;','&gt;','&lt;','&quot;'),array('&','>','<','"'),$string);
123 }
124
125 $encode=fixcharset($charset);
126 $encodefile=SM_PATH . 'functions/encode/' . $encode . '.php';
127 if (file_exists($encodefile)) {
128 include_once($encodefile);
129 $ret = call_user_func('charset_encode_'.$encode, $string);
130 } else {
131 include_once(SM_PATH . 'functions/encode/us_ascii.php');
132 $ret = charset_encode_us_ascii($string);
133 }
134 return( $ret );
135 }
136
137 /**
138 * Combined decoding and encoding functions
139 *
140 * If conversion is done to charset different that utf-8, unsupported symbols
141 * will be replaced with question marks.
142 * @param string $in_charset initial charset
143 * @param string $string string that has to be converted
144 * @param string $out_charset final charset
145 * @param boolean $htmlencode keep htmlspecialchars encoding
146 * @return string converted string
147 */
148 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
149 $string=charset_decode($in_charset,$string);
150 $string=charset_encode($string,$out_charset,$htmlencode);
151 return $string;
152 }
153
154 /**
155 * Makes charset name suitable for decoding cycles
156 *
157 * @param string $charset Name of charset
158 * @return string $charset Adjusted name of charset
159 */
160 function fixcharset($charset) {
161 // minus removed from function names
162 $charset=str_replace('-','_',$charset);
163
164 // windows-125x and cp125x charsets
165 $charset=str_replace('windows_','cp',$charset);
166
167 // ibm > cp
168 $charset=str_replace('ibm','cp',$charset);
169
170 // iso-8859-8-i -> iso-8859-8
171 // use same cycle until I'll find differences
172 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
173
174 return $charset;
175 }
176
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 *
182 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
183 * gettext translation bindings and html header information.
184 *
185 * Function returns error codes, if there is some fatal error.
186 * 0 = no error,
187 * 1 = mbstring support is not present,
188 * 2 = mbstring support is not present, user's translation reverted to en_US.
189 *
190 * @param string $sm_language translation used by user's interface
191 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
192 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
193 * @return int function execution error codes.
194 */
195 function set_up_language($sm_language, $do_search = false, $default = false) {
196
197 static $SetupAlready = 0;
198 global $use_gettext, $languages,
199 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
200 $sm_notAlias, $username, $data_dir;
201
202 if ($SetupAlready) {
203 return;
204 }
205
206 $SetupAlready = TRUE;
207 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
208
209 if ($do_search && ! $sm_language && isset($accept_lang)) {
210 $sm_language = substr($accept_lang, 0, 2);
211 }
212
213 if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
214 $squirrelmail_language = $squirrelmail_default_language;
215 $sm_language = $squirrelmail_default_language;
216 }
217 $sm_notAlias = $sm_language;
218
219 // Catching removed translation
220 // System reverts to English translation if user prefs contain translation
221 // that is not available in $languages array
222 if (!isset($languages[$sm_notAlias])) {
223 $sm_notAlias="en_US";
224 }
225
226 while (isset($languages[$sm_notAlias]['ALIAS'])) {
227 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
228 }
229
230 if ( isset($sm_language) &&
231 $use_gettext &&
232 $sm_language != '' &&
233 isset($languages[$sm_notAlias]['CHARSET']) ) {
234 bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
235 textdomain( 'squirrelmail' );
236 if (function_exists('bind_textdomain_codeset')) {
237 if ($sm_notAlias == 'ja_JP') {
238 bind_textdomain_codeset ("squirrelmail", 'EUC-JP');
239 } else {
240 bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
241 }
242 }
243 if (isset($languages[$sm_notAlias]['LOCALE'])){
244 $longlocale=$languages[$sm_notAlias]['LOCALE'];
245 } else {
246 $longlocale=$sm_notAlias;
247 }
248 if ( !ini_get('safe_mode') &&
249 getenv( 'LC_ALL' ) != $longlocale ) {
250 putenv( "LC_ALL=$longlocale" );
251 putenv( "LANG=$longlocale" );
252 putenv( "LANGUAGE=$longlocale" );
253 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
254 }
255 setlocale(LC_ALL, $longlocale);
256 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE,'C');
257
258 // Set text direction/alignment variables
259 if (isset($languages[$sm_notAlias]['DIR']) &&
260 $languages[$sm_notAlias]['DIR'] == 'rtl') {
261 /**
262 * Text direction
263 * @global string $text_direction
264 */
265 $text_direction='rtl';
266 /**
267 * Left alignment
268 * @global string $left_align
269 */
270 $left_align='right';
271 /**
272 * Right alignment
273 * @global string $right_align
274 */
275 $right_align='left';
276 } else {
277 $text_direction='ltr';
278 $left_align='left';
279 $right_align='right';
280 }
281
282 $squirrelmail_language = $sm_notAlias;
283 if ($squirrelmail_language == 'ja_JP') {
284 header ('Content-Type: text/html; charset=EUC-JP');
285 if (!function_exists('mb_internal_encoding')) {
286 // Error messages can't be displayed here
287 $error = 1;
288 // Revert to English if possible.
289 if (function_exists('setPref') && $username!='' && $data_dir!="") {
290 setPref($data_dir, $username, 'language', "en_US");
291 $error = 2;
292 }
293 // stop further execution in order not to get php errors on mb_internal_encoding().
294 return $error;
295 }
296 if (function_exists('mb_language')) {
297 mb_language('Japanese');
298 }
299 mb_internal_encoding('EUC-JP');
300 mb_http_output('pass');
301 } elseif ($squirrelmail_language == 'en_US') {
302 header( 'Content-Type: text/html; charset=' . $default_charset );
303 } else {
304 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
305 }
306 }
307 return 0;
308 }
309
310 /**
311 * Sets default_charset variable according to the one that is used by user's translations.
312 *
313 * Function changes global $default_charset variable in order to be sure, that it
314 * contains charset used by user's translation. Sanity of $squirrelmail_default_language
315 * and $default_charset combination provided in SquirrelMail config is also tested.
316 *
317 * There can be a $default_charset setting in the
318 * config.php file, but the user may have a different language
319 * selected for a user interface. This function checks the
320 * language selected by the user and tags the outgoing messages
321 * with the appropriate charset corresponding to the language
322 * selection. This is "more right" (tm), than just stamping the
323 * message blindly with the system-wide $default_charset.
324 */
325 function set_my_charset(){
326 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
327
328 $my_language = getPref($data_dir, $username, 'language');
329 if (!$my_language) {
330 $my_language = $squirrelmail_default_language ;
331 }
332 // Catch removed translation
333 if (!isset($languages[$my_language])) {
334 $my_language="en_US";
335 }
336 while (isset($languages[$my_language]['ALIAS'])) {
337 $my_language = $languages[$my_language]['ALIAS'];
338 }
339 $my_charset = $languages[$my_language]['CHARSET'];
340 if ($my_language!='en_US') {
341 $default_charset = $my_charset;
342 }
343 }
344
345 /* ------------------------------ main --------------------------- */
346
347 global $squirrelmail_language, $languages, $use_gettext;
348
349 if (! isset($squirrelmail_language)) {
350 $squirrelmail_language = '';
351 }
352
353 /**
354 * Array specifies the available translations.
355 *
356 * Structure of array:
357 * $languages['language']['variable'] = 'value'
358 *
359 * Possible 'variable' names:
360 * NAME - Translation name in English
361 * CHARSET - Encoding used by translation
362 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
363 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
364 * LOCALE - Full locale name (in xx_XX.charset format)
365 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
366 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
367 *
368 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
369 *
370 * @name $languages
371 * @global array $languages
372 */
373 $languages['bg_BG']['NAME'] = 'Bulgarian';
374 $languages['bg_BG']['ALTNAME'] = '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;';
375 $languages['bg_BG']['CHARSET'] = 'windows-1251';
376 $languages['bg_BG']['LOCALE'] = 'bg_BG.CP1251';
377 $languages['bg']['ALIAS'] = 'bg_BG';
378
379 $languages['ca_ES']['NAME'] = 'Catalan';
380 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
381 $languages['ca_ES']['LOCALE'] = 'ca_ES.ISO8859-1';
382 $languages['ca']['ALIAS'] = 'ca_ES';
383
384 $languages['cs_CZ']['NAME'] = 'Czech';
385 $languages['cs_CZ']['ALTNAME'] = '&#268;e&scaron;tina';
386 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
387 $languages['cs_CZ']['LOCALE'] = 'cs_CZ.ISO8859-2';
388 $languages['cs']['ALIAS'] = 'cs_CZ';
389
390 $languages['cy_GB']['NAME'] = 'Welsh';
391 $languages['cy_GB']['ALTNAME'] = 'Cymraeg';
392 $languages['cy_GB']['CHARSET'] = 'iso-8859-1';
393 $languages['cy_GB']['LOCALE'] = 'cy_GB.ISO8859-1';
394 $languages['cy']['ALIAS'] = 'cy_GB';
395
396 // Danish locale is da_DK.
397 $languages['da_DK']['NAME'] = 'Danish';
398 $languages['da_DK']['ALTNAME'] = 'Dansk';
399 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
400 $languages['da_DK']['LOCALE'] = 'da_DK.ISO8859-1';
401 $languages['da']['ALIAS'] = 'da_DK';
402
403 $languages['de_DE']['NAME'] = 'German';
404 $languages['de_DE']['ALTNAME'] = 'Deutsch';
405 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
406 $languages['de_DE']['LOCALE'] = 'de_DE.ISO8859-1';
407 $languages['de']['ALIAS'] = 'de_DE';
408
409 $languages['el_GR']['NAME'] = 'Greek';
410 $languages['el_GR']['ALTNAME'] = '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;';
411 $languages['el_GR']['CHARSET'] = 'iso-8859-7';
412 $languages['el_GR']['LOCALE'] = 'el_GR.ISO8859-7';
413 $languages['el']['ALIAS'] = 'el_GR';
414
415 $languages['en_GB']['NAME'] = 'British';
416 $languages['en_GB']['CHARSET'] = 'iso-8859-15';
417 $languages['en_GB']['LOCALE'] = 'en_GB.ISO8859-15';
418
419 $languages['en_US']['NAME'] = 'English';
420 $languages['en_US']['CHARSET'] = 'iso-8859-1';
421 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
422 $languages['en']['ALIAS'] = 'en_US';
423
424 $languages['es_ES']['NAME'] = 'Spanish';
425 $languages['es_ES']['ALTNAME'] = 'Espa&ntilde;ol';
426 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
427 $languages['es_ES']['LOCALE'] = 'es_ES.ISO8859-1';
428 $languages['es']['ALIAS'] = 'es_ES';
429
430 $languages['et_EE']['NAME'] = 'Estonian';
431 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
432 $languages['et_EE']['LOCALE'] = 'et_EE.ISO8859-15';
433 $languages['et']['ALIAS'] = 'et_EE';
434
435 $languages['eu_ES']['NAME'] = 'Basque';
436 $languages['eu_ES']['CHARSET'] = 'iso-8859-1';
437 $languages['eu_ES']['LOCALE'] = 'eu_ES.ISO8859-1';
438 $languages['eu']['ALIAS'] = 'eu_ES';
439
440 $languages['fo_FO']['NAME'] = 'Faroese';
441 $languages['fo_FO']['CHARSET'] = 'iso-8859-1';
442 $languages['fo_FO']['LOCALE'] = 'fo_FO.ISO8859-1';
443 $languages['fo']['ALIAS'] = 'fo_FO';
444
445 $languages['fi_FI']['NAME'] = 'Finnish';
446 $languages['fi_FI']['ALTNAME'] = 'Suomi';
447 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
448 $languages['fi_FI']['LOCALE'] = 'fi_FI.ISO8859-1';
449 $languages['fi']['ALIAS'] = 'fi_FI';
450
451 $languages['fr_FR']['NAME'] = 'French';
452 $languages['fr_FR']['ALTNAME'] = 'Fran&#231;ais';
453 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
454 $languages['fr_FR']['LOCALE'] = 'fr_FR.ISO8859-1';
455 $languages['fr']['ALIAS'] = 'fr_FR';
456
457 $languages['hr_HR']['NAME'] = 'Croatian';
458 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
459 $languages['hr_HR']['LOCALE'] = 'hr_HR.ISO8859-2';
460 $languages['hr']['ALIAS'] = 'hr_HR';
461
462 $languages['hu_HU']['NAME'] = 'Hungarian';
463 $languages['hu_HU']['ALTNAME'] = 'Magyar';
464 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
465 $languages['hu_HU']['LOCALE'] = 'hu_HU.ISO8859-2';
466 $languages['hu']['ALIAS'] = 'hu_HU';
467
468 $languages['id_ID']['NAME'] = 'Indonesian';
469 $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
470 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
471 $languages['id_ID']['LOCALE'] = 'id_ID.ISO8859-1';
472 $languages['id']['ALIAS'] = 'id_ID';
473
474 $languages['is_IS']['NAME'] = 'Icelandic';
475 $languages['is_IS']['ALTNAME'] = '&Iacute;slenska';
476 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
477 $languages['is_IS']['LOCALE'] = 'is_IS.ISO8859-1';
478 $languages['is']['ALIAS'] = 'is_IS';
479
480 $languages['it_IT']['NAME'] = 'Italian';
481 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
482 $languages['it_IT']['LOCALE'] = 'it_IT.ISO8859-1';
483 $languages['it']['ALIAS'] = 'it_IT';
484
485 $languages['ja_JP']['NAME'] = 'Japanese';
486 $languages['ja_JP']['ALTNAME'] = '&#26085;&#26412;&#35486;';
487 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
488 $languages['ja_JP']['LOCALE'] = 'ja_JP.EUC-JP';
489 $languages['ja_JP']['XTRA_CODE'] = 'japanese_xtra';
490 $languages['ja']['ALIAS'] = 'ja_JP';
491
492 $languages['ko_KR']['NAME'] = 'Korean';
493 $languages['ko_KR']['CHARSET'] = 'euc-KR';
494 $languages['ko_KR']['LOCALE'] = 'ko_KR.EUC-KR';
495 $languages['ko_KR']['XTRA_CODE'] = 'korean_xtra';
496 $languages['ko']['ALIAS'] = 'ko_KR';
497
498 $languages['lt_LT']['NAME'] = 'Lithuanian';
499 $languages['lt_LT']['ALTNAME'] = 'Lietuvi&#371;';
500 $languages['lt_LT']['CHARSET'] = 'utf-8';
501 $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
502 $languages['lt']['ALIAS'] = 'lt_LT';
503
504 $languages['nl_NL']['NAME'] = 'Dutch';
505 $languages['nl_NL']['ALTNAME'] = 'Nederlands';
506 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
507 $languages['nl_NL']['LOCALE'] = 'nl_NL.ISO8859-1';
508 $languages['nl']['ALIAS'] = 'nl_NL';
509
510 $languages['ms_MY']['NAME'] = 'Malay';
511 $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
512 $languages['ms_MY']['CHARSET'] = 'iso-8859-1';
513 $languages['ms_MY']['LOCALE'] = 'ms_MY.ISO8859-1';
514 $languages['my']['ALIAS'] = 'ms_MY';
515
516 $languages['nb_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
517 $languages['nb_NO']['ALTNAME'] = 'Norsk (Bokm&aring;l)';
518 $languages['nb_NO']['CHARSET'] = 'iso-8859-1';
519 $languages['nb_NO']['LOCALE'] = 'nb_NO.ISO8859-1';
520 $languages['nb']['ALIAS'] = 'nb_NO';
521
522 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
523 $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
524 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
525 $languages['nn_NO']['LOCALE'] = 'nn_NO.ISO8859-1';
526
527 $languages['pl_PL']['NAME'] = 'Polish';
528 $languages['pl_PL']['ALTNAME'] = 'Polski';
529 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
530 $languages['pl_PL']['LOCALE'] = 'pl_PL.ISO8859-2';
531 $languages['pl']['ALIAS'] = 'pl_PL';
532
533 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
534 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
535 $languages['pt_PT']['LOCALE'] = 'pt_PT.ISO8859-1';
536 $languages['pt']['ALIAS'] = 'pt_PT';
537
538 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
539 $languages['pt_BR']['ALTNAME'] = 'Portugu&ecirc;s do Brasil';
540 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
541 $languages['pt_BR']['LOCALE'] = 'pt_BR.ISO8859-1';
542
543 $languages['ro_RO']['NAME'] = 'Romanian';
544 $languages['ro_RO']['ALTNAME'] = 'Rom&acirc;n&#259;';
545 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
546 $languages['ro_RO']['LOCALE'] = 'ro_RO.ISO8859-2';
547 $languages['ro']['ALIAS'] = 'ro_RO';
548
549 $languages['ru_RU']['NAME'] = 'Russian';
550 $languages['ru_RU']['ALTNAME'] = '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;';
551 $languages['ru_RU']['CHARSET'] = 'utf-8';
552 $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
553 $languages['ru']['ALIAS'] = 'ru_RU';
554
555 $languages['sk_SK']['NAME'] = 'Slovak';
556 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
557 $languages['sk_SK']['LOCALE'] = 'sk_SK.ISO8859-2';
558 $languages['sk']['ALIAS'] = 'sk_SK';
559
560 $languages['sl_SI']['NAME'] = 'Slovenian';
561 $languages['sl_SI']['ALTNAME'] = 'Sloven&scaron;&#269;ina';
562 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
563 $languages['sl_SI']['LOCALE'] = 'sl_SI.ISO8859-2';
564 $languages['sl']['ALIAS'] = 'sl_SI';
565
566 $languages['sr_YU']['NAME'] = 'Serbian';
567 $languages['sr_YU']['ALTNAME'] = 'Srpski';
568 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
569 $languages['sr_YU']['LOCALE'] = 'sr_YU.ISO8859-2';
570 $languages['sr']['ALIAS'] = 'sr_YU';
571
572 $languages['sv_SE']['NAME'] = 'Swedish';
573 $languages['sv_SE']['ALTNAME'] = 'Svenska';
574 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
575 $languages['sv_SE']['LOCALE'] = 'sv_SE.ISO8859-1';
576 $languages['sv']['ALIAS'] = 'sv_SE';
577
578 $languages['th_TH']['NAME'] = 'Thai';
579 $languages['th_TH']['CHARSET'] = 'tis-620';
580 $languages['th_TH']['LOCALE'] = 'th_TH.TIS-620';
581 $languages['th']['ALIAS'] = 'th_TH';
582
583 $languages['tl_PH']['NAME'] = 'Tagalog';
584 $languages['tl_PH']['CHARSET'] = 'iso-8859-1';
585 $languages['tl_PH']['LOCALE'] = 'tl_PH.ISO8859-1';
586 $languages['tl']['ALIAS'] = 'tl_PH';
587
588 $languages['tr_TR']['NAME'] = 'Turkish';
589 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
590 $languages['tr_TR']['LOCALE'] = 'tr_TR.ISO8859-9';
591 $languages['tr']['ALIAS'] = 'tr_TR';
592
593 $languages['zh_TW']['NAME'] = 'Chinese Trad';
594 $languages['zh_TW']['CHARSET'] = 'big5';
595 $languages['zh_TW']['LOCALE'] = 'zh_TW.BIG5';
596 $languages['tw']['ALIAS'] = 'zh_TW';
597
598 $languages['zh_CN']['NAME'] = 'Chinese Simp';
599 $languages['zh_CN']['CHARSET'] = 'gb2312';
600 $languages['zh_CN']['LOCALE'] = 'zh_CN.GB2312';
601 $languages['cn']['ALIAS'] = 'zh_CN';
602
603 $languages['uk_UA']['NAME'] = 'Ukrainian';
604 $languages['uk_UA']['CHARSET'] = 'koi8-u';
605 $languages['uk_UA']['LOCALE'] = 'uk_UA.KOI8-U';
606 $languages['uk']['ALIAS'] = 'uk_UA';
607
608 $languages['ru_UA']['NAME'] = 'Russian (Ukrainian)';
609 $languages['ru_UA']['CHARSET'] = 'koi8-r';
610 $languages['ru_UA']['LOCALE'] = 'ru_UA.KOI8-R';
611
612 /*
613 $languages['vi_VN']['NAME'] = 'Vietnamese';
614 $languages['vi_VN']['CHARSET'] = 'utf-8';
615 $languages['vi']['ALIAS'] = 'vi_VN';
616 */
617
618 // Right to left languages
619 $languages['ar']['NAME'] = 'Arabic';
620 $languages['ar']['CHARSET'] = 'windows-1256';
621 $languages['ar']['DIR'] = 'rtl';
622
623 $languages['fa_IR']['NAME'] = 'Farsi';
624 $languages['fa_IR']['CHARSET'] = 'utf-8';
625 $languages['fa_IR']['DIR'] = 'rtl';
626 $languages['fa_IR']['LOCALE'] = 'fa_IR.UTF-8';
627 $languages['fa']['ALIAS'] = 'fa_IR';
628
629 $languages['he_IL']['NAME'] = 'Hebrew';
630 $languages['he_IL']['CHARSET'] = 'windows-1255';
631 $languages['he_IL']['LOCALE'] = 'he_IL.CP1255';
632 $languages['he_IL']['DIR'] = 'rtl';
633 $languages['he']['ALIAS'] = 'he_IL';
634
635 $languages['ug']['NAME'] = 'Uighur';
636 $languages['ug']['CHARSET'] = 'utf-8';
637 $languages['ug']['DIR'] = 'rtl';
638
639 /* Detect whether gettext is installed. */
640 $gettext_flags = 0;
641 if (function_exists('_')) {
642 $gettext_flags += 1;
643 }
644 if (function_exists('bindtextdomain')) {
645 $gettext_flags += 2;
646 }
647 if (function_exists('textdomain')) {
648 $gettext_flags += 4;
649 }
650
651 /* If gettext is fully loaded, cool */
652 if ($gettext_flags == 7) {
653 $use_gettext = true;
654 }
655 /* If we can fake gettext, try that */
656 elseif ($gettext_flags == 0) {
657 $use_gettext = true;
658 include_once(SM_PATH . 'functions/gettext.php');
659 } else {
660 /* Uh-ho. A weird install */
661 if (! $gettext_flags & 1) {
662 /**
663 * Function is used as replacement in broken installs
664 * @ignore
665 */
666 function _($str) {
667 return $str;
668 }
669 }
670 if (! $gettext_flags & 2) {
671 /**
672 * Function is used as replacement in broken installs
673 * @ignore
674 */
675 function bindtextdomain() {
676 return;
677 }
678 }
679 if (! $gettext_flags & 4) {
680 /**
681 * Function is used as replacemet in broken installs
682 * @ignore
683 */
684 function textdomain() {
685 return;
686 }
687 }
688 }
689
690
691 /**
692 * Japanese charset extra function
693 *
694 * Action performed by function is defined by first argument.
695 * Default return value is defined by second argument.
696 * Use of third argument depends on action.
697 *
698 * @param string $action action performed by this function.
699 * possible values:
700 * decode - convert returned string to euc-jp. third argument unused
701 * encode - convert returned string to jis. third argument unused
702 * strimwidth - third argument=$width. trims string to $width symbols.
703 * encodeheader - create base64 encoded header in iso-2022-jp. third argument unused
704 * decodeheader - return human readable string from mime header. string is returned in euc-jp. third argument unused
705 * downloadfilename - third argument $useragent. Arguments provide browser info. Returns shift-jis or euc-jp encoded file name
706 * wordwrap - third argument=$wrap. wraps text at $wrap symbols
707 * utf7-imap_encode - returns string converted from euc-jp to utf7-imap. third argument unused
708 * utf7-imap_decode - returns string converted from utf7-imap to euc-jp. third argument unused
709 * @param string $ret default return value
710 */
711 function japanese_xtra() {
712 $ret = func_get_arg(1); /* default return value */
713 if (function_exists('mb_detect_encoding')) {
714 switch (func_get_arg(0)) { /* action */
715 case 'decode':
716 $detect_encoding = @mb_detect_encoding($ret);
717 if ($detect_encoding == 'JIS' ||
718 $detect_encoding == 'EUC-JP' ||
719 $detect_encoding == 'SJIS' ||
720 $detect_encoding == 'UTF-8') {
721
722 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
723 }
724 break;
725 case 'encode':
726 $detect_encoding = @mb_detect_encoding($ret);
727 if ($detect_encoding == 'JIS' ||
728 $detect_encoding == 'EUC-JP' ||
729 $detect_encoding == 'SJIS' ||
730 $detect_encoding == 'UTF-8') {
731
732 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
733 }
734 break;
735 case 'strimwidth':
736 $width = func_get_arg(2);
737 $ret = mb_strimwidth($ret, 0, $width, '...');
738 break;
739 case 'encodeheader':
740 $result = '';
741 if (strlen($ret) > 0) {
742 $tmpstr = mb_substr($ret, 0, 1);
743 $prevcsize = strlen($tmpstr);
744 for ($i = 1; $i < mb_strlen($ret); $i++) {
745 $tmp = mb_substr($ret, $i, 1);
746 if (strlen($tmp) == $prevcsize) {
747 $tmpstr .= $tmp;
748 } else {
749 if ($prevcsize == 1) {
750 $result .= $tmpstr;
751 } else {
752 $result .= str_replace(' ', '',
753 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
754 }
755 $tmpstr = $tmp;
756 $prevcsize = strlen($tmp);
757 }
758 }
759 if (strlen($tmpstr)) {
760 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
761 $result .= $tmpstr;
762 else
763 $result .= str_replace(' ', '',
764 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
765 }
766 }
767 $ret = $result;
768 break;
769 case 'decodeheader':
770 $ret = str_replace("\t", "", $ret);
771 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
772 $ret = @mb_decode_mimeheader($ret);
773 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
774 break;
775 case 'downloadfilename':
776 $useragent = func_get_arg(2);
777 if (strstr($useragent, 'Windows') !== false ||
778 strstr($useragent, 'Mac_') !== false) {
779 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
780 } else {
781 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
782 }
783 break;
784 case 'wordwrap':
785 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
786 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
787 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
788 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
789 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
790 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
791 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
792 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
793 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
794 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
795 $wrap = func_get_arg(2);
796
797 if (strlen($ret) >= $wrap &&
798 substr($ret, 0, 1) != '>' &&
799 strpos($ret, 'http://') === FALSE &&
800 strpos($ret, 'https://') === FALSE &&
801 strpos($ret, 'ftp://') === FALSE) {
802
803 $ret = mb_convert_kana($ret, "KV");
804
805 $line_new = '';
806 $ptr = 0;
807
808 while ($ptr < strlen($ret) - 1) {
809 $l = mb_strcut($ret, $ptr, $wrap);
810 $ptr += strlen($l);
811 $tmp = $l;
812
813 $l = mb_strcut($ret, $ptr, 2);
814 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
815 $tmp .= $l;
816 $ptr += strlen($l);
817 $l = mb_strcut($ret, $ptr, 1);
818 }
819 $line_new .= $tmp;
820 if ($ptr < strlen($ret) - 1)
821 $line_new .= "\n";
822 }
823 $ret = $line_new;
824 }
825 break;
826 case 'utf7-imap_encode':
827 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
828 break;
829 case 'utf7-imap_decode':
830 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
831 break;
832 }
833 }
834 return $ret;
835 }
836
837 /**************************
838 * Japanese extra functions
839 **************************/
840
841 /**
842 * Japanese decoding function
843 *
844 * converts string to euc-jp, if string uses JIS, EUC-JP, ShiftJIS or UTF-8
845 * charset. Needs mbstring support in php.
846 * @param string $ret text, that has to be converted
847 * @return string converted string
848 * @since 1.5.1
849 */
850 function japanese_xtra_decode($ret) {
851 if (function_exists('mb_detect_encoding')) {
852 $detect_encoding = @mb_detect_encoding($ret);
853 if ($detect_encoding == 'JIS' ||
854 $detect_encoding == 'EUC-JP' ||
855 $detect_encoding == 'SJIS' ||
856 $detect_encoding == 'UTF-8') {
857
858 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
859 }
860 }
861 return $ret;
862 }
863
864 /**
865 * Japanese encoding function
866 *
867 * converts string to jis, if string uses JIS, EUC-JP, ShiftJIS or UTF-8
868 * charset. Needs mbstring support in php.
869 * @param string $ret text, that has to be converted
870 * @return string converted text
871 * @since 1.5.1
872 */
873 function japanese_xtra_encode($ret) {
874 if (function_exists('mb_detect_encoding')) {
875 $detect_encoding = @mb_detect_encoding($ret);
876 if ($detect_encoding == 'JIS' ||
877 $detect_encoding == 'EUC-JP' ||
878 $detect_encoding == 'SJIS' ||
879 $detect_encoding == 'UTF-8') {
880
881 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
882 }
883 }
884 return $ret;
885 }
886
887 /**
888 * Japanese header encoding function
889 *
890 * creates base64 encoded header in iso-2022-jp charset
891 * @param string $ret text, that has to be converted
892 * @return string mime base64 encoded string
893 * @since 1.5.1
894 */
895 function japanese_xtra_encodeheader($ret) {
896 if (function_exists('mb_detect_encoding')) {
897 $result = '';
898 if (strlen($ret) > 0) {
899 $tmpstr = mb_substr($ret, 0, 1);
900 $prevcsize = strlen($tmpstr);
901 for ($i = 1; $i < mb_strlen($ret); $i++) {
902 $tmp = mb_substr($ret, $i, 1);
903 if (strlen($tmp) == $prevcsize) {
904 $tmpstr .= $tmp;
905 } else {
906 if ($prevcsize == 1) {
907 $result .= $tmpstr;
908 } else {
909 $result .= str_replace(' ', '',
910 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
911 }
912 $tmpstr = $tmp;
913 $prevcsize = strlen($tmp);
914 }
915 }
916 if (strlen($tmpstr)) {
917 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
918 $result .= $tmpstr;
919 else
920 $result .= str_replace(' ', '',
921 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
922 }
923 }
924 $ret = $result;
925 }
926 return $ret;
927 }
928
929 /**
930 * Japanese header decoding function
931 *
932 * return human readable string from mime header. string is returned in euc-jp
933 * charset.
934 * @param string $ret header string
935 * @return string decoded header string
936 * @since 1.5.1
937 */
938 function japanese_xtra_decodeheader($ret) {
939 if (function_exists('mb_detect_encoding')) {
940 $ret = str_replace("\t", "", $ret);
941 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
942 $ret = @mb_decode_mimeheader($ret);
943 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
944 }
945 return $ret;
946 }
947
948 /**
949 * Japanese downloaded filename processing function
950 *
951 * Returns shift-jis or euc-jp encoded file name
952 * @param string $ret string
953 * @param string $useragent browser
954 * @return string converted string
955 * @since 1.5.1
956 */
957 function japanese_xtra_downloadfilename($ret,$useragent) {
958 if (function_exists('mb_detect_encoding')) {
959 if (strstr($useragent, 'Windows') !== false ||
960 strstr($useragent, 'Mac_') !== false) {
961 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
962 } else {
963 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
964 }
965 }
966 return $ret;
967 }
968
969 /**
970 * Japanese wordwrap function
971 *
972 * wraps text at set number of symbols
973 * @param string $ret text
974 * @param integer $wrap number of symbols per line
975 * @return string wrapped text
976 * @since 1.5.1
977 */
978 function japanese_xtra_wordwrap($ret,$wrap) {
979 if (function_exists('mb_detect_encoding')) {
980 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
981 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
982 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
983 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
984 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
985 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
986 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
987 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
988 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
989 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
990
991 if (strlen($ret) >= $wrap &&
992 substr($ret, 0, 1) != '>' &&
993 strpos($ret, 'http://') === FALSE &&
994 strpos($ret, 'https://') === FALSE &&
995 strpos($ret, 'ftp://') === FALSE) {
996
997 $ret = mb_convert_kana($ret, "KV");
998
999 $line_new = '';
1000 $ptr = 0;
1001
1002 while ($ptr < strlen($ret) - 1) {
1003 $l = mb_strcut($ret, $ptr, $wrap);
1004 $ptr += strlen($l);
1005 $tmp = $l;
1006
1007 $l = mb_strcut($ret, $ptr, 2);
1008 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
1009 $tmp .= $l;
1010 $ptr += strlen($l);
1011 $l = mb_strcut($ret, $ptr, 1);
1012 }
1013 $line_new .= $tmp;
1014 if ($ptr < strlen($ret) - 1)
1015 $line_new .= "\n";
1016 }
1017 $ret = $line_new;
1018 }
1019 }
1020 return $ret;
1021 }
1022
1023 /**
1024 * Japanese imap folder name encoding function
1025 *
1026 * converts folder name from euc-jp to utf7-imap
1027 * @param string $ret folder name
1028 * @return string converted folder name
1029 * @since 1.5.1
1030 */
1031 function japanese_xtra_utf7_imap_encode($ret){
1032 if (function_exists('mb_detect_encoding')) {
1033 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
1034 }
1035 return $ret;
1036 }
1037
1038 /**
1039 * Japanese imap folder name decoding function
1040 *
1041 * converts folder name from utf7-imap to euc-jp.
1042 * @param string $ret folder name in utf7-imap
1043 * @return string converted folder name
1044 * @since 1.5.1
1045 */
1046 function japanese_xtra_utf7_imap_decode($ret) {
1047 if (function_exists('mb_detect_encoding')) {
1048 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
1049 }
1050 return $ret;
1051 }
1052
1053 /**
1054 * Japanese string trimming function
1055 *
1056 * trims string to defined number of symbols
1057 * @param string $ret string
1058 * @param integer $width number of symbols
1059 * @return string trimmed string
1060 * @since 1.5.1
1061 */
1062 function japanese_xtra_strimwidth($ret,$width) {
1063 if (function_exists('mb_detect_encoding')) {
1064 $ret = mb_strimwidth($ret, 0, $width, '...');
1065 }
1066 return $ret;
1067 }
1068
1069 /********************************
1070 * Korean charset extra functions
1071 ********************************/
1072
1073 /**
1074 * Korean downloaded filename processing functions
1075 *
1076 * @param string default return value
1077 * @return string
1078 */
1079 function korean_xtra_downloadfilename($ret) {
1080 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
1081 for ($i=0;$i<strlen($ret);$i++) {
1082 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
1083 $i++;
1084 continue;
1085 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
1086 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
1087 ($ret[$i] == '.') || ($ret[$i] == '-')) {
1088 continue;
1089 } else {
1090 $ret[$i] = '_';
1091 }
1092 }
1093 return $ret;
1094 }
1095
1096 /**
1097 * Replaces non-braking spaces inserted by some browsers with regular space
1098 *
1099 * This function can be used to replace non-braking space symbols
1100 * that are inserted in forms by some browsers instead of normal
1101 * space symbol.
1102 *
1103 * @param string $string Text that needs to be cleaned
1104 * @param string $charset Charset used in text
1105 * @return string Cleaned text
1106 */
1107 function cleanup_nbsp($string,$charset) {
1108
1109 // reduce number of case statements
1110 if (stristr('iso-8859-',substr($charset,0,9))){
1111 $output_charset="iso-8859-x";
1112 }
1113 if (stristr('windows-125',substr($charset,0,11))){
1114 $output_charset="cp125x";
1115 }
1116 if (stristr('koi8',substr($charset,0,4))){
1117 $output_charset="koi8-x";
1118 }
1119 if (! isset($output_charset)){
1120 $output_charset=strtolower($charset);
1121 }
1122
1123 // where is non-braking space symbol
1124 switch($output_charset):
1125 case "iso-8859-x":
1126 case "cp125x":
1127 case "iso-2022-jp":
1128 $nbsp="\xA0";
1129 break;
1130 case "koi8-x":
1131 $nbsp="\x9A";
1132 break;
1133 case "utf-8":
1134 $nbsp="\xC2\xA0";
1135 break;
1136 default:
1137 // don't change string if charset is unmatched
1138 return $string;
1139 endswitch;
1140
1141 // return space instead of non-braking space.
1142 return str_replace($nbsp,' ',$string);
1143 }
1144
1145 /**
1146 * Function informs if it is safe to convert given charset to the one that is used by user.
1147 *
1148 * It is safe to use conversion only if user uses utf-8 encoding and when
1149 * converted charset is similar to the one that is used by user.
1150 *
1151 * @param string $input_charset Charset of text that needs to be converted
1152 * @return bool is it possible to convert to user's charset
1153 */
1154 function is_conversion_safe($input_charset) {
1155 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
1156
1157 if (isset($lossy_encoding) && $lossy_encoding )
1158 return true;
1159
1160 // convert to lower case
1161 $input_charset = strtolower($input_charset);
1162
1163 // Is user's locale Unicode based ?
1164 if ( $default_charset == "utf-8" ) {
1165 return true;
1166 }
1167
1168 // Charsets that are similar
1169 switch ($default_charset):
1170 case "windows-1251":
1171 if ( $input_charset == "iso-8859-5" ||
1172 $input_charset == "koi8-r" ||
1173 $input_charset == "koi8-u" ) {
1174 return true;
1175 } else {
1176 return false;
1177 }
1178 case "windows-1257":
1179 if ( $input_charset == "iso-8859-13" ||
1180 $input_charset == "iso-8859-4" ) {
1181 return true;
1182 } else {
1183 return false;
1184 }
1185 case "iso-8859-4":
1186 if ( $input_charset == "iso-8859-13" ||
1187 $input_charset == "windows-1257" ) {
1188 return true;
1189 } else {
1190 return false;
1191 }
1192 case "iso-8859-5":
1193 if ( $input_charset == "windows-1251" ||
1194 $input_charset == "koi8-r" ||
1195 $input_charset == "koi8-u" ) {
1196 return true;
1197 } else {
1198 return false;
1199 }
1200 case "iso-8859-13":
1201 if ( $input_charset == "iso-8859-4" ||
1202 $input_charset == "windows-1257" ) {
1203 return true;
1204 } else {
1205 return false;
1206 }
1207 case "koi8-r":
1208 if ( $input_charset == "windows-1251" ||
1209 $input_charset == "iso-8859-5" ||
1210 $input_charset == "koi8-u" ) {
1211 return true;
1212 } else {
1213 return false;
1214 }
1215 case "koi8-u":
1216 if ( $input_charset == "windows-1251" ||
1217 $input_charset == "iso-8859-5" ||
1218 $input_charset == "koi8-r" ) {
1219 return true;
1220 } else {
1221 return false;
1222 }
1223 default:
1224 return false;
1225 endswitch;
1226 }
1227 ?>