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