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