342b9336af15c1cfeb299c036017d61004a64eb8
4 * SquirrelMail internationalization functions
6 * This file contains variuos functions that are needed to do
7 * internationalization of SquirrelMail.
9 * Internally the output character set is used. Other characters are
10 * encoded using Unicode entities according to HTML 4.0.
12 * @copyright © 1999-2006 The SquirrelMail Project Team
13 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15 * @package squirrelmail
21 * Gettext bindtextdomain wrapper.
23 * Wrapper solves differences between php versions in order to provide
24 * ngettext support. Should be used if translation uses ngettext
27 * @param string $domain gettext domain name
28 * @param string $dir directory that contains all translations
29 * @return string path to translation directory
31 function sq_bindtextdomain($domain,$dir) {
32 global $l10n, $gettext_flags, $sm_notAlias;
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);
42 $dir=bindtextdomain($domain,$dir);
48 * Gettext textdomain wrapper.
49 * Makes sure that gettext_domain global is modified.
51 * @param string $name gettext domain name
52 * @return string gettext domain name
54 function sq_textdomain($domain) {
55 global $gettext_domain;
56 $gettext_domain=textdomain($domain);
57 return $gettext_domain;
61 * php setlocale function wrapper
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.
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
74 function sq_setlocale($category,$locale) {
75 // string with only one locale
76 if (is_string($locale))
77 return setlocale($category,$locale);
79 if (! check_php_version(4,3)) {
82 while ( ! $ret && $index<count($locale)) {
83 $ret=setlocale($category,$locale[$index]);
87 // php 4.3.0 or better, use entire array
88 $ret=setlocale($category,$locale);
94 * Converts string from given charset to charset, that can be displayed by user translation.
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.
101 * sanitizing of html tags is also done by this function.
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
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;
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);
120 $charset = strtolower($charset);
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; }
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));
134 // catch iso-8859-8-i thing
135 if ( $charset == "iso-8859-8-i" )
136 $charset = "iso-8859-8";
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.
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));
150 $string = recode_string($charset . "..html",$string);
151 // recode does not convert single quote, htmlspecialchars does.
152 $string = str_replace("'", ''', $string);
153 // undo html specialchars
155 $string=str_replace(array('&','"','<','>'),
156 array('&','"','<','>'),$string);
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));
167 // If we don't use recode and iconv, we'll do it old way.
169 /* All HTML special characters are 7 bit and can be replaced first */
170 if (! $save_html) $string = htmlspecialchars ($string);
172 /* controls cpu and memory intensive decoding cycles */
173 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
174 $aggressive_decoding=false; }
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);
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
196 function charset_encode($string,$charset,$htmlencode=true) {
197 global $default_charset;
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);
211 * fix for yahoo users that remove all us-ascii related things
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.
222 if (! $htmlencode ) {
223 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
229 * Combined decoding and encoding functions
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
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);
248 * Makes charset name suitable for decoding cycles
250 * @since 1.5.0 and 1.4.4
251 * @param string $charset Name of charset
252 * @return string $charset Adjusted name of charset
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.
258 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
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);
267 // windows-125x and cp125x charsets
268 $charset=str_replace('windows_','cp',$charset);
271 $charset=str_replace('ibm','cp',$charset);
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);
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
285 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
286 * gettext translation bindings and html header information.
288 * Function returns error codes, if there is some fatal error.
290 * 1 = mbstring support is not present,
291 * 2 = mbstring support is not present, user's translation reverted to en_US.
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.
298 function set_up_language($sm_language, $do_search = false, $default = false) {
300 static $SetupAlready = 0;
301 global $use_gettext, $languages,
302 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
303 $sm_notAlias, $username, $data_dir;
309 $SetupAlready = TRUE;
310 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
313 * If function is asked to detect preferred language
314 * OR squirrelmail default language is set to empty string
316 * squirrelmail language ($sm_language) is empty string
317 * (not set in user's prefs and no cookie with language info)
319 * browser provides list of preferred languages
321 * get preferred language from HTTP_ACCEPT_LANGUAGE header
323 if (($do_search ||
empty($squirrelmail_default_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);
333 * If language preference is not set OR script asks to use default language
335 * default squirrelmail language is not set to empty string
337 * use default squirrelmail language value from configuration.
339 if ((!$sm_language||
$default) &&
340 ! empty($squirrelmail_default_language)) {
341 $squirrelmail_language = $squirrelmail_default_language;
342 $sm_language = $squirrelmail_default_language;
345 /** provide failsafe language when detection fails */
346 if (! $sm_language) $sm_language='en_US';
348 $sm_notAlias = $sm_language;
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";
357 while (isset($languages[$sm_notAlias]['ALIAS'])) {
358 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
361 if ( isset($sm_language) &&
363 $sm_language != '' &&
364 isset($languages[$sm_notAlias]['CHARSET']) ) {
365 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
366 sq_textdomain( 'squirrelmail' );
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');
374 bind_textdomain_codeset ('squirrelmail', $languages[$sm_notAlias]['CHARSET'] );
378 // Use LOCALE key, if it is set.
379 if (isset($languages[$sm_notAlias]['LOCALE'])){
380 $longlocale=$languages[$sm_notAlias]['LOCALE'];
382 $longlocale=$sm_notAlias;
385 // try setting locale
386 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
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;
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" );
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');
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
420 global $text_direction, $left_align, $right_align;
421 if (isset($languages[$sm_notAlias]['DIR']) &&
422 $languages[$sm_notAlias]['DIR'] == 'rtl') {
425 * @global string $text_direction
427 $text_direction='rtl';
430 * @global string $left_align
435 * @global string $right_align
439 $text_direction='ltr';
441 $right_align='right';
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
450 // Revert to English if possible.
451 if (function_exists('setPref') && $username!='' && $data_dir!="") {
452 setPref($data_dir, $username, 'language', "en_US");
455 // stop further execution in order not to get php errors on mb_internal_encoding().
458 if (function_exists('mb_language')) {
459 mb_language('Japanese');
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 );
466 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
469 * mbstring.func_overload fix (#929644).
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
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.
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.
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');
494 * Sets default_charset variable according to the one that is used by user's translations.
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.
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.
508 function set_my_charset(){
509 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
511 $my_language = getPref($data_dir, $username, 'language');
513 $my_language = $squirrelmail_language ;
515 // Catch removed translation
516 if (!isset($languages[$my_language])) {
517 $my_language="en_US";
519 while (isset($languages[$my_language]['ALIAS'])) {
520 $my_language = $languages[$my_language]['ALIAS'];
522 $my_charset = $languages[$my_language]['CHARSET'];
523 if ($my_language!='en_US') {
524 $default_charset = $my_charset;
529 * Replaces non-braking spaces inserted by some browsers with regular space
531 * This function can be used to replace non-braking space symbols
532 * that are inserted in forms by some browsers instead of normal
535 * @param string $string Text that needs to be cleaned
536 * @param string $charset Charset used in text
537 * @return string Cleaned text
539 function cleanup_nbsp($string,$charset) {
541 // reduce number of case statements
542 if (stristr('iso-8859-',substr($charset,0,9))){
543 $output_charset="iso-8859-x";
545 if (stristr('windows-125',substr($charset,0,11))){
546 $output_charset="cp125x";
548 if (stristr('koi8',substr($charset,0,4))){
549 $output_charset="koi8-x";
551 if (! isset($output_charset)){
552 $output_charset=strtolower($charset);
555 // where is non-braking space symbol
556 switch($output_charset):
569 // don't change string if charset is unmatched
573 // return space instead of non-braking space.
574 return str_replace($nbsp,' ',$string);
578 * Function informs if it is safe to convert given charset to the one that is used by user.
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.
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
586 function is_conversion_safe($input_charset) {
587 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
589 if (isset($lossy_encoding) && $lossy_encoding )
592 // convert to lower case
593 $input_charset = strtolower($input_charset);
595 // Is user's locale Unicode based ?
596 if ( $default_charset == "utf-8" ) {
600 // Charsets that are similar
601 switch ($default_charset) {
603 if ( $input_charset == "iso-8859-5" ||
604 $input_charset == "koi8-r" ||
605 $input_charset == "koi8-u" ) {
611 if ( $input_charset == "iso-8859-13" ||
612 $input_charset == "iso-8859-4" ) {
618 if ( $input_charset == "iso-8859-13" ||
619 $input_charset == "windows-1257" ) {
625 if ( $input_charset == "windows-1251" ||
626 $input_charset == "koi8-r" ||
627 $input_charset == "koi8-u" ) {
633 if ( $input_charset == "iso-8859-4" ||
634 $input_charset == "windows-1257" ) {
640 if ( $input_charset == "windows-1251" ||
641 $input_charset == "iso-8859-5" ||
642 $input_charset == "koi8-u" ) {
648 if ( $input_charset == "windows-1251" ||
649 $input_charset == "iso-8859-5" ||
650 $input_charset == "koi8-r" ) {
661 * Converts html character entities to numeric entities
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()
668 * @param string $str string that might contain html character entities
669 * @return string string with character entities converted to decimals.
672 function sqi18n_convert_entities($str) {
676 ' ' => ' ',
677 '¡' => '¡',
678 '¢' => '¢',
679 '£' => '£',
680 '¤' => '¤',
682 '¦' => '¦',
683 '§' => '§',
685 '©' => '©',
686 'ª' => 'ª',
687 '«' => '«',
691 '¯' => '¯',
693 '±' => '±',
694 '²' => '²',
695 '³' => '³',
696 '´' => '´',
697 'µ' => 'µ',
698 '¶' => '¶',
699 '·' => '·',
700 '¸' => '¸',
701 '¹' => '¹',
702 'º' => 'º',
703 '»' => '»',
704 '¼' => '¼',
705 '½' => '½',
706 '¾' => '¾',
707 '¿' => '¿',
708 'À' => 'À',
709 'Á' => 'Á',
710 'Â' => 'Â',
711 'Ã' => 'Ã',
712 'Ä' => 'Ä',
713 'Å' => 'Å',
714 'Æ' => 'Æ',
715 'Ç' => 'Ç',
716 'È' => 'È',
717 'É' => 'É',
718 'Ê' => 'Ê',
719 'Ë' => 'Ë',
720 'Ì' => 'Ì',
721 'Í' => 'Í',
722 'Î' => 'Î',
723 'Ï' => 'Ï',
725 'Ñ' => 'Ñ',
726 'Ò' => 'Ò',
727 'Ó' => 'Ó',
728 'Ô' => 'Ô',
729 'Õ' => 'Õ',
730 'Ö' => 'Ö',
731 '×' => '×',
732 'Ø' => 'Ø',
733 'Ù' => 'Ù',
734 'Ú' => 'Ú',
735 'Û' => 'Û',
736 'Ü' => 'Ü',
737 'Ý' => 'Ý',
738 'Þ' => 'Þ',
739 'ß' => 'ß',
740 'à' => 'à',
741 'á' => 'á',
742 'â' => 'â',
743 'ã' => 'ã',
744 'ä' => 'ä',
745 'å' => 'å',
746 'æ' => 'æ',
747 'ç' => 'ç',
748 'è' => 'è',
749 'é' => 'é',
750 'ê' => 'ê',
751 'ë' => 'ë',
752 'ì' => 'ì',
753 'í' => 'í',
754 'î' => 'î',
755 'ï' => 'ï',
757 'ñ' => 'ñ',
758 'ò' => 'ò',
759 'ó' => 'ó',
760 'ô' => 'ô',
761 'õ' => 'õ',
762 'ö' => 'ö',
763 '÷' => '÷',
764 'ø' => 'ø',
765 'ù' => 'ù',
766 'ú' => 'ú',
767 'û' => 'û',
768 'ü' => 'ü',
769 'ý' => 'ý',
770 'þ' => 'þ',
771 'ÿ' => 'ÿ',
773 'Œ' => 'Œ',
774 'œ' => 'œ',
775 'Š' => 'Š',
776 'š' => 'š',
777 'Ÿ' => 'Ÿ',
778 // Spacing Modifier Letters
779 'ˆ' => 'ˆ',
780 '˜' => '˜',
781 // General Punctuation
782 ' ' => ' ',
783 ' ' => ' ',
784 ' ' => ' ',
785 '‌' => '‌',
786 '‍' => '‍',
787 '‎' => '‎',
788 '‏' => '‏',
789 '–' => '–',
790 '—' => '—',
791 '‘' => '‘',
792 '’' => '’',
793 '‚' => '‚',
794 '“' => '“',
795 '”' => '”',
796 '„' => '„',
797 '†' => '†',
798 '‡' => '‡',
799 '‰' => '‰',
800 '‹' => '‹',
801 '›' => '›',
802 '€' => '€',
804 'ƒ' => 'ƒ',
806 'Α' => 'Α',
807 'Β' => 'Β',
808 'Γ' => 'Γ',
809 'Δ' => 'Δ',
810 'Ε' => 'Ε',
811 'Ζ' => 'Ζ',
813 'Θ' => 'Θ',
814 'Ι' => 'Ι',
815 'Κ' => 'Κ',
816 'Λ' => 'Λ',
820 'Ο' => 'Ο',
823 'Σ' => 'Σ',
825 'Υ' => 'Υ',
829 'Ω' => 'Ω',
830 'α' => 'α',
831 'β' => 'β',
832 'γ' => 'γ',
833 'δ' => 'δ',
834 'ε' => 'ε',
835 'ζ' => 'ζ',
837 'θ' => 'θ',
838 'ι' => 'ι',
839 'κ' => 'κ',
840 'λ' => 'λ',
844 'ο' => 'ο',
847 'ς' => 'ς',
848 'σ' => 'σ',
850 'υ' => 'υ',
854 'ω' => 'ω',
855 'ϑ' => 'ϑ',
856 'ϒ' => 'ϒ',
858 // General Punctuation
859 '•' => '•',
860 '…' => '…',
861 '′' => '′',
862 '″' => '″',
863 '‾' => '‾',
864 '⁄' => '⁄',
865 // Letterlike Symbols
866 '℘' => '℘',
867 'ℑ' => 'ℑ',
868 'ℜ' => 'ℜ',
869 '™' => '™',
870 'ℵ' => 'ℵ',
872 '←' => '←',
873 '↑' => '↑',
874 '→' => '→',
875 '↓' => '↓',
876 '↔' => '↔',
877 '↵' => '↵',
878 '⇐' => '⇐',
879 '⇑' => '⇑',
880 '⇒' => '⇒',
881 '⇓' => '⇓',
882 '⇔' => '⇔',
883 // Mathematical Operators
884 '∀' => '∀',
885 '∂' => '∂',
886 '∃' => '∃',
887 '∅' => '∅',
888 '∇' => '∇',
889 '∈' => '∈',
890 '∉' => '∉',
892 '∏' => '∏',
893 '∑' => '∑',
894 '−' => '−',
895 '∗' => '∗',
896 '√' => '√',
897 '∝' => '∝',
898 '∞' => '∞',
899 '∠' => '∠',
900 '∧' => '∧',
902 '∩' => '∩',
903 '∪' => '∪',
904 '∫' => '∫',
905 '∴' => '∴',
906 '∼' => '∼',
907 '≅' => '≅',
908 '≈' => '≈',
910 '≡' => '≡',
913 '⊂' => '⊂',
914 '⊃' => '⊃',
915 '⊄' => '⊄',
916 '⊆' => '⊆',
917 '⊇' => '⊇',
918 '⊕' => '⊕',
919 '⊗' => '⊗',
920 '⊥' => '⊥',
921 '⋅' => '⋅',
922 // Miscellaneous Technical
923 '⌈' => '⌈',
924 '⌉' => '⌉',
925 '⌊' => '⌊',
926 '⌋' => '⌋',
927 '⟨' => '〈',
928 '⟩' => '〉',
930 '◊' => '◊',
931 // Miscellaneous Symbols
932 '♠' => '♠',
933 '♣' => '♣',
934 '♥' => '♥',
935 '♦' => '♦');
937 $str = str_replace(array_keys($entities), array_values($entities), $str);
942 /* ------------------------------ main --------------------------- */
944 global $squirrelmail_language, $languages, $use_gettext;
946 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
947 $squirrelmail_language = '';
951 * Array specifies the available translations.
953 * Structure of array:
954 * $languages['language']['variable'] = 'value'
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
965 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
968 * @global array $languages
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';
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.
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);
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');
997 /* Detect whether gettext is installed. */
999 if (function_exists('_')) {
1000 $gettext_flags +
= 1;
1002 if (function_exists('bindtextdomain')) {
1003 $gettext_flags +
= 2;
1005 if (function_exists('textdomain')) {
1006 $gettext_flags +
= 4;
1008 if (function_exists('ngettext')) {
1009 $gettext_flags +
= 8;
1012 /* If gettext is fully loaded, cool */
1013 if ($gettext_flags == 15) {
1014 $use_gettext = true;
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');
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');
1030 /* Uh-ho. A weird install */
1031 if (! $gettext_flags & 1) {
1033 * Function is used as replacement in broken installs
1040 if (! $gettext_flags & 2) {
1042 * Function is used as replacement in broken installs
1045 function bindtextdomain() {
1049 if (! $gettext_flags & 4) {
1051 * Function is used as replacemet in broken installs
1054 function textdomain() {
1058 if (! $gettext_flags & 8) {
1060 * Function is used as replacemet in broken installs
1063 function ngettext($str,$str2,$number) {
1071 if (! function_exists('dgettext')) {
1073 * Replacement for broken setups.
1076 function dgettext($domain,$str) {
1080 if (! function_exists('dngettext')) {
1082 * Replacement for broken setups
1085 function dngettext($domain,$str1,$strn,$number) {
1086 return ($number==1 ?
$str1 : $strn);