Centralized init
[squirrelmail.git] / include / languages.php
1 <?php
2
3 /**
4 * SquirrelMail internationalization functions
5 *
6 * This file contains variuos functions that are needed to do
7 * internationalization of SquirrelMail.
8 *
9 * Internally the output character set is used. Other characters are
10 * encoded using Unicode entities according to HTML 4.0.
11 *
12 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
13 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 * @version $Id$
15 * @package squirrelmail
16 * @subpackage i18n
17 */
18
19
20 /**
21 * Gettext bindtextdomain wrapper.
22 *
23 * Wrapper solves differences between php versions in order to provide
24 * ngettext support. Should be used if translation uses ngettext
25 * functions.
26 * @since 1.5.1
27 * @param string $domain gettext domain name
28 * @param string $dir directory that contains all translations
29 * @return string path to translation directory
30 */
31 function sq_bindtextdomain($domain,$dir) {
32 global $l10n, $gettext_flags, $sm_notAlias;
33
34 if ($gettext_flags==7) {
35 // gettext extension without ngettext
36 if (substr($dir, -1) != '/') $dir .= '/';
37 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
38 $input = new FileReader($mofile);
39 $l10n[$domain] = new gettext_reader($input);
40 }
41
42 $dir=bindtextdomain($domain,$dir);
43
44 return $dir;
45 }
46
47 /**
48 * Gettext textdomain wrapper.
49 * Makes sure that gettext_domain global is modified.
50 * @since 1.5.1
51 * @param string $name gettext domain name
52 * @return string gettext domain name
53 */
54 function sq_textdomain($domain) {
55 global $gettext_domain;
56 $gettext_domain=textdomain($domain);
57 return $gettext_domain;
58 }
59
60 /**
61 * php setlocale function wrapper
62 *
63 * From php 4.3.0 it is possible to use arrays in order to set locale.
64 * php gettext extension works only when locale is set. This wrapper
65 * function allows to use more than one locale name.
66 *
67 * @param int $category locale category name. Use php named constants
68 * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME)
69 * @param mixed $locale option contains array with possible locales or string with one locale
70 * @return string name of set locale or false, if all locales fail.
71 * @since 1.5.1 and 1.4.5
72 * @see http://www.php.net/setlocale
73 */
74 function sq_setlocale($category,$locale) {
75 // string with only one locale
76 if (is_string($locale))
77 return setlocale($category,$locale);
78
79 if (! check_php_version(4,3)) {
80 $ret=false;
81 $index=0;
82 while ( ! $ret && $index<count($locale)) {
83 $ret=setlocale($category,$locale[$index]);
84 $index++;
85 }
86 } else {
87 // php 4.3.0 or better, use entire array
88 $ret=setlocale($category,$locale);
89 }
90 return $ret;
91 }
92
93 /**
94 * Converts string from given charset to charset, that can be displayed by user translation.
95 *
96 * Function by default returns html encoded strings, if translation uses different encoding.
97 * If Japanese translation is used - function returns string converted to euc-jp
98 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
99 * If $charset is not supported - function returns unconverted string.
100 *
101 * sanitizing of html tags is also done by this function.
102 *
103 * @param string $charset
104 * @param string $string Text to be decoded
105 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
106 * Argument is available since 1.5.1 and 1.4.5.
107 * @param boolean $save_html disables htmlspecialchars() in order to preserve
108 * html formating. Use with care. Available since 1.5.1
109 * @return string decoded string
110 */
111 function charset_decode ($charset, $string, $force_decode=false, $save_html=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 ($save_html ? $string : 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 ($save_html ? $string : 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 // undo html specialchars
154 if ($save_html)
155 $string=str_replace(array('&amp;','&quot;','&lt;','&gt;'),
156 array('&','"','<','>'),$string);
157 return $string;
158 }
159 }
160
161 // iconv functions does not have html target and can be used only with utf-8
162 if ( $use_php_iconv && $default_charset=='utf-8') {
163 $string = iconv($charset,$default_charset,$string);
164 return ($save_html ? $string : htmlspecialchars($string));
165 }
166
167 // If we don't use recode and iconv, we'll do it old way.
168
169 /* All HTML special characters are 7 bit and can be replaced first */
170 if (! $save_html) $string = htmlspecialchars ($string);
171
172 /* controls cpu and memory intensive decoding cycles */
173 if (! isset($aggressive_decoding) || $aggressive_decoding=="" ) {
174 $aggressive_decoding=false; }
175
176 $decode=fixcharset($charset);
177 $decodefile=SM_PATH . 'functions/decode/' . $decode . '.php';
178 if (file_exists($decodefile)) {
179 include_once($decodefile);
180 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
181 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
182 } else {
183 $ret = $string;
184 }
185 return( $ret );
186 }
187
188 /**
189 * Converts html string to given charset
190 * @since 1.5.1 and 1.4.4
191 * @param string $string
192 * @param string $charset
193 * @param boolean $htmlencode keep htmlspecialchars encoding
194 * @param string
195 */
196 function charset_encode($string,$charset,$htmlencode=true) {
197 global $default_charset;
198
199 $encode=fixcharset($charset);
200 $encodefile=SM_PATH . 'functions/encode/' . $encode . '.php';
201 if (file_exists($encodefile)) {
202 include_once($encodefile);
203 $ret = call_user_func('charset_encode_'.$encode, $string);
204 } elseif(file_exists(SM_PATH . 'functions/encode/us_ascii.php')) {
205 // function replaces all 8bit html entities with question marks.
206 // it is used when other encoding functions are unavailable
207 include_once(SM_PATH . 'functions/encode/us_ascii.php');
208 $ret = charset_encode_us_ascii($string);
209 } else {
210 /**
211 * fix for yahoo users that remove all us-ascii related things
212 */
213 $ret = $string;
214 }
215
216 /**
217 * Undo html special chars, some places (like compose form) have
218 * own sanitizing functions and don't need html symbols.
219 * Undo chars only after encoding in order to prevent conversion of
220 * html entities in plain text emails.
221 */
222 if (! $htmlencode ) {
223 $ret = str_replace(array('&amp;','&gt;','&lt;','&quot;'),array('&','>','<','"'),$ret);
224 }
225 return( $ret );
226 }
227
228 /**
229 * Combined decoding and encoding functions
230 *
231 * If conversion is done to charset different that utf-8, unsupported symbols
232 * will be replaced with question marks.
233 * @since 1.5.1 and 1.4.4
234 * @param string $in_charset initial charset
235 * @param string $string string that has to be converted
236 * @param string $out_charset final charset
237 * @param boolean $htmlencode keep htmlspecialchars encoding
238 * @return string converted string
239 */
240 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
241 $string=charset_decode($in_charset,$string,true);
242 $string=sqi18n_convert_entities($string);
243 $string=charset_encode($string,$out_charset,$htmlencode);
244 return $string;
245 }
246
247 /**
248 * Makes charset name suitable for decoding cycles
249 *
250 * @since 1.5.0 and 1.4.4
251 * @param string $charset Name of charset
252 * @return string $charset Adjusted name of charset
253 */
254 function fixcharset($charset) {
255 /* remove minus and characters that might be used in paths from charset
256 * name in order to be able to use it in function names and include calls.
257 */
258 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
259
260 // OE ks_c_5601_1987 > cp949
261 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
262 // Moz x-euc-tw > euc-tw
263 $charset=str_replace('x_euc','euc',$charset);
264 // Moz x-windows-949 > cp949
265 $charset=str_replace('x_windows_','cp',$charset);
266
267 // windows-125x and cp125x charsets
268 $charset=str_replace('windows_','cp',$charset);
269
270 // ibm > cp
271 $charset=str_replace('ibm','cp',$charset);
272
273 // iso-8859-8-i -> iso-8859-8
274 // use same cycle until I'll find differences
275 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
276
277 return $charset;
278 }
279
280 /**
281 * Set up the language to be output
282 * if $do_search is true, then scan the browser information
283 * for a possible language that we know
284 *
285 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
286 * gettext translation bindings and html header information.
287 *
288 * Function returns error codes, if there is some fatal error.
289 * 0 = no error,
290 * 1 = mbstring support is not present,
291 * 2 = mbstring support is not present, user's translation reverted to en_US.
292 *
293 * @param string $sm_language translation used by user's interface
294 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
295 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
296 * @return int function execution error codes.
297 */
298 function set_up_language($sm_language, $do_search = false, $default = false) {
299
300 static $SetupAlready = 0;
301 global $use_gettext, $languages,
302 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
303 $sm_notAlias, $username, $data_dir;
304
305 if ($SetupAlready) {
306 return;
307 }
308
309 $SetupAlready = TRUE;
310 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
311
312 /**
313 * If function is asked to detect preferred language
314 * OR squirrelmail default language is set to empty string
315 * AND
316 * squirrelmail language ($sm_language) is empty string
317 * (not set in user's prefs and no cookie with language info)
318 * AND
319 * browser provides list of preferred languages
320 * THEN
321 * get preferred language from HTTP_ACCEPT_LANGUAGE header
322 */
323 if (($do_search || empty($squirrelmail_default_language)) &&
324 ! $sm_language &&
325 isset($accept_lang)) {
326 // TODO: use more than one language, if first language is not available
327 // FIXME: function assumes that string contains two or more characters.
328 // FIXME: some languages use 5 chars
329 $sm_language = substr($accept_lang, 0, 2);
330 }
331
332 /**
333 * If language preference is not set OR script asks to use default language
334 * AND
335 * default squirrelmail language is not set to empty string
336 * THEN
337 * use default squirrelmail language value from configuration.
338 */
339 if ((!$sm_language||$default) &&
340 ! empty($squirrelmail_default_language)) {
341 $squirrelmail_language = $squirrelmail_default_language;
342 $sm_language = $squirrelmail_default_language;
343 }
344
345 /** provide failsafe language when detection fails */
346 if (! $sm_language) $sm_language='en_US';
347
348 $sm_notAlias = $sm_language;
349
350 // Catching removed translation
351 // System reverts to English translation if user prefs contain translation
352 // that is not available in $languages array
353 if (!isset($languages[$sm_notAlias])) {
354 $sm_notAlias="en_US";
355 }
356
357 while (isset($languages[$sm_notAlias]['ALIAS'])) {
358 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
359 }
360
361 if ( isset($sm_language) &&
362 $use_gettext &&
363 $sm_language != '' &&
364 isset($languages[$sm_notAlias]['CHARSET']) ) {
365 sq_bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
366 sq_textdomain( 'squirrelmail' );
367
368 // set codeset in order to avoid gettext charset conversions
369 if (function_exists('bind_textdomain_codeset')) {
370 // Japanese translation uses different internal charset
371 if ($sm_notAlias == 'ja_JP') {
372 bind_textdomain_codeset ('squirrelmail', 'EUC-JP');
373 } else {
374 bind_textdomain_codeset ('squirrelmail', $languages[$sm_notAlias]['CHARSET'] );
375 }
376 }
377
378 // Use LOCALE key, if it is set.
379 if (isset($languages[$sm_notAlias]['LOCALE'])){
380 $longlocale=$languages[$sm_notAlias]['LOCALE'];
381 } else {
382 $longlocale=$sm_notAlias;
383 }
384
385 // try setting locale
386 $retlocale=sq_setlocale(LC_ALL, $longlocale);
387
388 // check if locale is set and assign that locale to $longlocale
389 // in order to use it in putenv calls.
390 if (! is_bool($retlocale)) {
391 $longlocale=$retlocale;
392 } elseif (is_array($longlocale)) {
393 // setting of all locales failed.
394 // we need string instead of array used in LOCALE key.
395 $longlocale=$sm_notAlias;
396 }
397
398 if ( !((bool)ini_get('safe_mode')) &&
399 getenv( 'LC_ALL' ) != $longlocale ) {
400 putenv( "LC_ALL=$longlocale" );
401 putenv( "LANG=$longlocale" );
402 putenv( "LANGUAGE=$longlocale" );
403 putenv( "LC_NUMERIC=C" );
404 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
405 }
406 // Workaround for plugins that use numbers with floating point
407 // It might be removed if plugins use correct decimal delimiters
408 // according to locale settings.
409 setlocale(LC_NUMERIC, 'C');
410 // Workaround for specific Turkish strtolower/strtoupper rules.
411 // Many functions expect English conversion rules.
412 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE,'C');
413
414 /**
415 * Set text direction/alignment variables
416 * When language environment is setup, scripts can use these globals
417 * without accessing $languages directly and making checks for optional
418 * array key.
419 */
420 global $text_direction, $left_align, $right_align;
421 if (isset($languages[$sm_notAlias]['DIR']) &&
422 $languages[$sm_notAlias]['DIR'] == 'rtl') {
423 /**
424 * Text direction
425 * @global string $text_direction
426 */
427 $text_direction='rtl';
428 /**
429 * Left alignment
430 * @global string $left_align
431 */
432 $left_align='right';
433 /**
434 * Right alignment
435 * @global string $right_align
436 */
437 $right_align='left';
438 } else {
439 $text_direction='ltr';
440 $left_align='left';
441 $right_align='right';
442 }
443
444 $squirrelmail_language = $sm_notAlias;
445 if ($squirrelmail_language == 'ja_JP') {
446 header ('Content-Type: text/html; charset=EUC-JP');
447 if (!function_exists('mb_internal_encoding')) {
448 // Error messages can't be displayed here
449 $error = 1;
450 // Revert to English if possible.
451 if (function_exists('setPref') && $username!='' && $data_dir!="") {
452 setPref($data_dir, $username, 'language', "en_US");
453 $error = 2;
454 }
455 // stop further execution in order not to get php errors on mb_internal_encoding().
456 return $error;
457 }
458 if (function_exists('mb_language')) {
459 mb_language('Japanese');
460 }
461 mb_internal_encoding('EUC-JP');
462 mb_http_output('pass');
463 } elseif ($squirrelmail_language == 'en_US') {
464 header( 'Content-Type: text/html; charset=' . $default_charset );
465 } else {
466 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
467 }
468 /**
469 * mbstring.func_overload fix (#929644).
470 *
471 * php mbstring extension can replace standard string functions with their multibyte
472 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
473 * was added in php v.4.2.0
474 *
475 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
476 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
477 * interface can't trust regular string functions. Due to mbstring overloading design
478 * limits php scripts can't control this setting.
479 *
480 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
481 * to disable mbstring overloading. Japanese translation uses different internal encoding.
482 */
483 if ($squirrelmail_language != 'ja_JP' &&
484 function_exists('mb_internal_encoding') &&
485 check_php_version(4,2,0) &&
486 (int)ini_get('mbstring.func_overload')!=0) {
487 mb_internal_encoding('pass');
488 }
489 }
490 return 0;
491 }
492
493 /**
494 * Sets default_charset variable according to the one that is used by user's translations.
495 *
496 * Function changes global $default_charset variable in order to be sure, that it
497 * contains charset used by user's translation. Sanity of $squirrelmail_language
498 * and $default_charset combination is also tested.
499 *
500 * There can be a $default_charset setting in the
501 * config.php file, but the user may have a different language
502 * selected for a user interface. This function checks the
503 * language selected by the user and tags the outgoing messages
504 * with the appropriate charset corresponding to the language
505 * selection. This is "more right" (tm), than just stamping the
506 * message blindly with the system-wide $default_charset.
507 */
508 function set_my_charset(){
509 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
510
511 $my_language = getPref($data_dir, $username, 'language');
512 if (!$my_language) {
513 $my_language = $squirrelmail_language ;
514 }
515 // Catch removed translation
516 if (!isset($languages[$my_language])) {
517 $my_language="en_US";
518 }
519 while (isset($languages[$my_language]['ALIAS'])) {
520 $my_language = $languages[$my_language]['ALIAS'];
521 }
522 $my_charset = $languages[$my_language]['CHARSET'];
523 if ($my_language!='en_US') {
524 $default_charset = $my_charset;
525 }
526 }
527
528 /**
529 * Replaces non-braking spaces inserted by some browsers with regular space
530 *
531 * This function can be used to replace non-braking space symbols
532 * that are inserted in forms by some browsers instead of normal
533 * space symbol.
534 *
535 * @param string $string Text that needs to be cleaned
536 * @param string $charset Charset used in text
537 * @return string Cleaned text
538 */
539 function cleanup_nbsp($string,$charset) {
540
541 // reduce number of case statements
542 if (stristr('iso-8859-',substr($charset,0,9))){
543 $output_charset="iso-8859-x";
544 }
545 if (stristr('windows-125',substr($charset,0,11))){
546 $output_charset="cp125x";
547 }
548 if (stristr('koi8',substr($charset,0,4))){
549 $output_charset="koi8-x";
550 }
551 if (! isset($output_charset)){
552 $output_charset=strtolower($charset);
553 }
554
555 // where is non-braking space symbol
556 switch($output_charset):
557 case "iso-8859-x":
558 case "cp125x":
559 case "iso-2022-jp":
560 $nbsp="\xA0";
561 break;
562 case "koi8-x":
563 $nbsp="\x9A";
564 break;
565 case "utf-8":
566 $nbsp="\xC2\xA0";
567 break;
568 default:
569 // don't change string if charset is unmatched
570 return $string;
571 endswitch;
572
573 // return space instead of non-braking space.
574 return str_replace($nbsp,' ',$string);
575 }
576
577 /**
578 * Function informs if it is safe to convert given charset to the one that is used by user.
579 *
580 * It is safe to use conversion only if user uses utf-8 encoding and when
581 * converted charset is similar to the one that is used by user.
582 *
583 * @param string $input_charset Charset of text that needs to be converted
584 * @return bool is it possible to convert to user's charset
585 */
586 function is_conversion_safe($input_charset) {
587 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
588
589 if (isset($lossy_encoding) && $lossy_encoding )
590 return true;
591
592 // convert to lower case
593 $input_charset = strtolower($input_charset);
594
595 // Is user's locale Unicode based ?
596 if ( $default_charset == "utf-8" ) {
597 return true;
598 }
599
600 // Charsets that are similar
601 switch ($default_charset) {
602 case "windows-1251":
603 if ( $input_charset == "iso-8859-5" ||
604 $input_charset == "koi8-r" ||
605 $input_charset == "koi8-u" ) {
606 return true;
607 } else {
608 return false;
609 }
610 case "windows-1257":
611 if ( $input_charset == "iso-8859-13" ||
612 $input_charset == "iso-8859-4" ) {
613 return true;
614 } else {
615 return false;
616 }
617 case "iso-8859-4":
618 if ( $input_charset == "iso-8859-13" ||
619 $input_charset == "windows-1257" ) {
620 return true;
621 } else {
622 return false;
623 }
624 case "iso-8859-5":
625 if ( $input_charset == "windows-1251" ||
626 $input_charset == "koi8-r" ||
627 $input_charset == "koi8-u" ) {
628 return true;
629 } else {
630 return false;
631 }
632 case "iso-8859-13":
633 if ( $input_charset == "iso-8859-4" ||
634 $input_charset == "windows-1257" ) {
635 return true;
636 } else {
637 return false;
638 }
639 case "koi8-r":
640 if ( $input_charset == "windows-1251" ||
641 $input_charset == "iso-8859-5" ||
642 $input_charset == "koi8-u" ) {
643 return true;
644 } else {
645 return false;
646 }
647 case "koi8-u":
648 if ( $input_charset == "windows-1251" ||
649 $input_charset == "iso-8859-5" ||
650 $input_charset == "koi8-r" ) {
651 return true;
652 } else {
653 return false;
654 }
655 default:
656 return false;
657 }
658 }
659
660 /**
661 * Converts html character entities to numeric entities
662 *
663 * SquirrelMail encoding functions work only with numeric entities.
664 * This function fixes issues with decoding functions that might convert
665 * some symbols to character entities. Issue is specific to PHP recode
666 * extension decoding. Function is used internally in charset_convert()
667 * function.
668 * @param string $str string that might contain html character entities
669 * @return string string with character entities converted to decimals.
670 * @since 1.5.2
671 */
672 function sqi18n_convert_entities($str) {
673
674 $entities = array(
675 // Latin 1
676 '&nbsp;' => '&#160;',
677 '&iexcl;' => '&#161;',
678 '&cent;' => '&#162;',
679 '&pound;' => '&#163;',
680 '&curren;' => '&#164;',
681 '&yen;' => '&#165;',
682 '&brvbar;' => '&#166;',
683 '&sect;' => '&#167;',
684 '&uml;' => '&#168;',
685 '&copy;' => '&#169;',
686 '&ordf;' => '&#170;',
687 '&laquo;' => '&#171;',
688 '&not;' => '&#172;',
689 '&shy;' => '&#173;',
690 '&reg;' => '&#174;',
691 '&macr;' => '&#175;',
692 '&deg;' => '&#176;',
693 '&plusmn;' => '&#177;',
694 '&sup2;' => '&#178;',
695 '&sup3;' => '&#179;',
696 '&acute;' => '&#180;',
697 '&micro;' => '&#181;',
698 '&para;' => '&#182;',
699 '&middot;' => '&#183;',
700 '&cedil;' => '&#184;',
701 '&sup1;' => '&#185;',
702 '&ordm;' => '&#186;',
703 '&raquo;' => '&#187;',
704 '&frac14;' => '&#188;',
705 '&frac12;' => '&#189;',
706 '&frac34;' => '&#190;',
707 '&iquest;' => '&#191;',
708 '&Agrave;' => '&#192;',
709 '&Aacute;' => '&#193;',
710 '&Acirc;' => '&#194;',
711 '&Atilde;' => '&#195;',
712 '&Auml;' => '&#196;',
713 '&Aring;' => '&#197;',
714 '&AElig;' => '&#198;',
715 '&Ccedil;' => '&#199;',
716 '&Egrave;' => '&#200;',
717 '&Eacute;' => '&#201;',
718 '&Ecirc;' => '&#202;',
719 '&Euml;' => '&#203;',
720 '&Igrave;' => '&#204;',
721 '&Iacute;' => '&#205;',
722 '&Icirc;' => '&#206;',
723 '&Iuml;' => '&#207;',
724 '&ETH;' => '&#208;',
725 '&Ntilde;' => '&#209;',
726 '&Ograve;' => '&#210;',
727 '&Oacute;' => '&#211;',
728 '&Ocirc;' => '&#212;',
729 '&Otilde;' => '&#213;',
730 '&Ouml;' => '&#214;',
731 '&times;' => '&#215;',
732 '&Oslash;' => '&#216;',
733 '&Ugrave;' => '&#217;',
734 '&Uacute;' => '&#218;',
735 '&Ucirc;' => '&#219;',
736 '&Uuml;' => '&#220;',
737 '&Yacute;' => '&#221;',
738 '&THORN;' => '&#222;',
739 '&szlig;' => '&#223;',
740 '&agrave;' => '&#224;',
741 '&aacute;' => '&#225;',
742 '&acirc;' => '&#226;',
743 '&atilde;' => '&#227;',
744 '&auml;' => '&#228;',
745 '&aring;' => '&#229;',
746 '&aelig;' => '&#230;',
747 '&ccedil;' => '&#231;',
748 '&egrave;' => '&#232;',
749 '&eacute;' => '&#233;',
750 '&ecirc;' => '&#234;',
751 '&euml;' => '&#235;',
752 '&igrave;' => '&#236;',
753 '&iacute;' => '&#237;',
754 '&icirc;' => '&#238;',
755 '&iuml;' => '&#239;',
756 '&eth;' => '&#240;',
757 '&ntilde;' => '&#241;',
758 '&ograve;' => '&#242;',
759 '&oacute;' => '&#243;',
760 '&ocirc;' => '&#244;',
761 '&otilde;' => '&#245;',
762 '&ouml;' => '&#246;',
763 '&divide;' => '&#247;',
764 '&oslash;' => '&#248;',
765 '&ugrave;' => '&#249;',
766 '&uacute;' => '&#250;',
767 '&ucirc;' => '&#251;',
768 '&uuml;' => '&#252;',
769 '&yacute;' => '&#253;',
770 '&thorn;' => '&#254;',
771 '&yuml;' => '&#255;',
772 // Latin Extended-A
773 '&OElig;' => '&#338;',
774 '&oelig;' => '&#339;',
775 '&Scaron;' => '&#352;',
776 '&scaron;' => '&#353;',
777 '&Yuml;' => '&#376;',
778 // Spacing Modifier Letters
779 '&circ;' => '&#710;',
780 '&tilde;' => '&#732;',
781 // General Punctuation
782 '&ensp;' => '&#8194;',
783 '&emsp;' => '&#8195;',
784 '&thinsp;' => '&#8201;',
785 '&zwnj;' => '&#8204;',
786 '&zwj;' => '&#8205;',
787 '&lrm;' => '&#8206;',
788 '&rlm;' => '&#8207;',
789 '&ndash;' => '&#8211;',
790 '&mdash;' => '&#8212;',
791 '&lsquo;' => '&#8216;',
792 '&rsquo;' => '&#8217;',
793 '&sbquo;' => '&#8218;',
794 '&ldquo;' => '&#8220;',
795 '&rdquo;' => '&#8221;',
796 '&bdquo;' => '&#8222;',
797 '&dagger;' => '&#8224;',
798 '&Dagger;' => '&#8225;',
799 '&permil;' => '&#8240;',
800 '&lsaquo;' => '&#8249;',
801 '&rsaquo;' => '&#8250;',
802 '&euro;' => '&#8364;',
803 // Latin Extended-B
804 '&fnof;' => '&#402;',
805 // Greek
806 '&Alpha;' => '&#913;',
807 '&Beta;' => '&#914;',
808 '&Gamma;' => '&#915;',
809 '&Delta;' => '&#916;',
810 '&Epsilon;' => '&#917;',
811 '&Zeta;' => '&#918;',
812 '&Eta;' => '&#919;',
813 '&Theta;' => '&#920;',
814 '&Iota;' => '&#921;',
815 '&Kappa;' => '&#922;',
816 '&Lambda;' => '&#923;',
817 '&Mu;' => '&#924;',
818 '&Nu;' => '&#925;',
819 '&Xi;' => '&#926;',
820 '&Omicron;' => '&#927;',
821 '&Pi;' => '&#928;',
822 '&Rho;' => '&#929;',
823 '&Sigma;' => '&#931;',
824 '&Tau;' => '&#932;',
825 '&Upsilon;' => '&#933;',
826 '&Phi;' => '&#934;',
827 '&Chi;' => '&#935;',
828 '&Psi;' => '&#936;',
829 '&Omega;' => '&#937;',
830 '&alpha;' => '&#945;',
831 '&beta;' => '&#946;',
832 '&gamma;' => '&#947;',
833 '&delta;' => '&#948;',
834 '&epsilon;' => '&#949;',
835 '&zeta;' => '&#950;',
836 '&eta;' => '&#951;',
837 '&theta;' => '&#952;',
838 '&iota;' => '&#953;',
839 '&kappa;' => '&#954;',
840 '&lambda;' => '&#955;',
841 '&mu;' => '&#956;',
842 '&nu;' => '&#957;',
843 '&xi;' => '&#958;',
844 '&omicron;' => '&#959;',
845 '&pi;' => '&#960;',
846 '&rho;' => '&#961;',
847 '&sigmaf;' => '&#962;',
848 '&sigma;' => '&#963;',
849 '&tau;' => '&#964;',
850 '&upsilon;' => '&#965;',
851 '&phi;' => '&#966;',
852 '&chi;' => '&#967;',
853 '&psi;' => '&#968;',
854 '&omega;' => '&#969;',
855 '&thetasym;' => '&#977;',
856 '&upsih;' => '&#978;',
857 '&piv;' => '&#982;',
858 // General Punctuation
859 '&bull;' => '&#8226;',
860 '&hellip;' => '&#8230;',
861 '&prime;' => '&#8242;',
862 '&Prime;' => '&#8243;',
863 '&oline;' => '&#8254;',
864 '&frasl;' => '&#8260;',
865 // Letterlike Symbols
866 '&weierp;' => '&#8472;',
867 '&image;' => '&#8465;',
868 '&real;' => '&#8476;',
869 '&trade;' => '&#8482;',
870 '&alefsym;' => '&#8501;',
871 // Arrows
872 '&larr;' => '&#8592;',
873 '&uarr;' => '&#8593;',
874 '&rarr;' => '&#8594;',
875 '&darr;' => '&#8595;',
876 '&harr;' => '&#8596;',
877 '&crarr;' => '&#8629;',
878 '&lArr;' => '&#8656;',
879 '&uArr;' => '&#8657;',
880 '&rArr;' => '&#8658;',
881 '&dArr;' => '&#8659;',
882 '&hArr;' => '&#8660;',
883 // Mathematical Operators
884 '&forall;' => '&#8704;',
885 '&part;' => '&#8706;',
886 '&exist;' => '&#8707;',
887 '&empty;' => '&#8709;',
888 '&nabla;' => '&#8711;',
889 '&isin;' => '&#8712;',
890 '&notin;' => '&#8713;',
891 '&ni;' => '&#8715;',
892 '&prod;' => '&#8719;',
893 '&sum;' => '&#8721;',
894 '&minus;' => '&#8722;',
895 '&lowast;' => '&#8727;',
896 '&radic;' => '&#8730;',
897 '&prop;' => '&#8733;',
898 '&infin;' => '&#8734;',
899 '&ang;' => '&#8736;',
900 '&and;' => '&#8743;',
901 '&or;' => '&#8744;',
902 '&cap;' => '&#8745;',
903 '&cup;' => '&#8746;',
904 '&int;' => '&#8747;',
905 '&there4;' => '&#8756;',
906 '&sim;' => '&#8764;',
907 '&cong;' => '&#8773;',
908 '&asymp;' => '&#8776;',
909 '&ne;' => '&#8800;',
910 '&equiv;' => '&#8801;',
911 '&le;' => '&#8804;',
912 '&ge;' => '&#8805;',
913 '&sub;' => '&#8834;',
914 '&sup;' => '&#8835;',
915 '&nsub;' => '&#8836;',
916 '&sube;' => '&#8838;',
917 '&supe;' => '&#8839;',
918 '&oplus;' => '&#8853;',
919 '&otimes;' => '&#8855;',
920 '&perp;' => '&#8869;',
921 '&sdot;' => '&#8901;',
922 // Miscellaneous Technical
923 '&lceil;' => '&#8968;',
924 '&rceil;' => '&#8969;',
925 '&lfloor;' => '&#8970;',
926 '&rfloor;' => '&#8971;',
927 '&lang;' => '&#9001;',
928 '&rang;' => '&#9002;',
929 // Geometric Shapes
930 '&loz;' => '&#9674;',
931 // Miscellaneous Symbols
932 '&spades;' => '&#9824;',
933 '&clubs;' => '&#9827;',
934 '&hearts;' => '&#9829;',
935 '&diams;' => '&#9830;');
936
937 $str = str_replace(array_keys($entities), array_values($entities), $str);
938
939 return $str;
940 }
941
942 /* ------------------------------ main --------------------------- */
943
944 global $squirrelmail_language, $languages, $use_gettext;
945
946 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE)) {
947 $squirrelmail_language = '';
948 }
949
950 /**
951 * Array specifies the available translations.
952 *
953 * Structure of array:
954 * $languages['language']['variable'] = 'value'
955 *
956 * Possible 'variable' names:
957 * NAME - Translation name in English
958 * CHARSET - Encoding used by translation
959 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
960 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
961 * LOCALE - Full locale name (in xx_XX.charset format). It can use array with more than one locale name since 1.4.5 and 1.5.1
962 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
963 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
964 *
965 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
966 *
967 * @name $languages
968 * @global array $languages
969 */
970 $languages['en_US']['NAME'] = 'English';
971 $languages['en_US']['CHARSET'] = 'iso-8859-1';
972 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
973 $languages['en']['ALIAS'] = 'en_US';
974
975 /**
976 * Automatic translation loading from setup.php files.
977 * Solution for bug. 1240889.
978 * setup.php file can contain $languages array entries and XTRA_CODE functions.
979 */
980 if (is_dir(SM_PATH . 'locale') &&
981 is_readable(SM_PATH . 'locale')) {
982 $localedir = dir(SM_PATH . 'locale');
983 while($lang_dir=$localedir->read()) {
984 // remove trailing slash, if present
985 if (substr($lang_dir,-1)=='/') {
986 $lang_dir = substr($lang_dir,0,-1);
987 }
988 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
989 is_dir(SM_PATH.'locale/'.$lang_dir) &&
990 file_exists(SM_PATH.'locale/'.$lang_dir.'/setup.php')) {
991 include_once(SM_PATH.'locale/'.$lang_dir.'/setup.php');
992 }
993 }
994 $localedir->close();
995 }
996
997 /* Detect whether gettext is installed. */
998 $gettext_flags = 0;
999 if (function_exists('_')) {
1000 $gettext_flags += 1;
1001 }
1002 if (function_exists('bindtextdomain')) {
1003 $gettext_flags += 2;
1004 }
1005 if (function_exists('textdomain')) {
1006 $gettext_flags += 4;
1007 }
1008 if (function_exists('ngettext')) {
1009 $gettext_flags += 8;
1010 }
1011
1012 /* If gettext is fully loaded, cool */
1013 if ($gettext_flags == 15) {
1014 $use_gettext = true;
1015 }
1016
1017 /* If ngettext support is missing, load it */
1018 elseif ($gettext_flags == 7) {
1019 $use_gettext = true;
1020 // load internal ngettext functions
1021 include_once(SM_PATH . 'class/l10n.class.php');
1022 include_once(SM_PATH . 'functions/ngettext.php');
1023 }
1024
1025 /* If we can fake gettext, try that */
1026 elseif ($gettext_flags == 0) {
1027 $use_gettext = true;
1028 include_once(SM_PATH . 'functions/gettext.php');
1029 } else {
1030 /* Uh-ho. A weird install */
1031 if (! $gettext_flags & 1) {
1032 /**
1033 * Function is used as replacement in broken installs
1034 * @ignore
1035 */
1036 function _($str) {
1037 return $str;
1038 }
1039 }
1040 if (! $gettext_flags & 2) {
1041 /**
1042 * Function is used as replacement in broken installs
1043 * @ignore
1044 */
1045 function bindtextdomain() {
1046 return;
1047 }
1048 }
1049 if (! $gettext_flags & 4) {
1050 /**
1051 * Function is used as replacemet in broken installs
1052 * @ignore
1053 */
1054 function textdomain() {
1055 return;
1056 }
1057 }
1058 if (! $gettext_flags & 8) {
1059 /**
1060 * Function is used as replacemet in broken installs
1061 * @ignore
1062 */
1063 function ngettext($str,$str2,$number) {
1064 if ($number>1) {
1065 return $str2;
1066 } else {
1067 return $str;
1068 }
1069 }
1070 }
1071 if (! function_exists('dgettext')) {
1072 /**
1073 * Replacement for broken setups.
1074 * @ignore
1075 */
1076 function dgettext($domain,$str) {
1077 return $str;
1078 }
1079 }
1080 if (! function_exists('dngettext')) {
1081 /**
1082 * Replacement for broken setups
1083 * @ignore
1084 */
1085 function dngettext($domain,$str1,$strn,$number) {
1086 return ($number==1 ? $str1 : $strn);
1087 }
1088 }
1089 }
1090 ?>