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