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