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
20 if (! defined('SM_PATH')) define('SM_PATH','../');
22 /** Everything uses global.php... */
23 require_once(SM_PATH
. 'functions/global.php');
26 * Gettext bindtextdomain wrapper.
28 * Wrapper solves differences between php versions in order to provide
29 * ngettext support. Should be used if translation uses ngettext
32 * @param string $domain gettext domain name
33 * @param string $dir directory that contains all translations
34 * @return string path to translation directory
36 function sq_bindtextdomain($domain,$dir) {
37 global $l10n, $gettext_flags, $sm_notAlias;
39 if ($gettext_flags==7) {
40 // gettext extension without ngettext
41 if (substr($dir, -1) != '/') $dir .= '/';
42 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
43 $input = new FileReader($mofile);
44 $l10n[$domain] = new gettext_reader($input);
47 $dir=bindtextdomain($domain,$dir);
53 * Gettext textdomain wrapper.
54 * Makes sure that gettext_domain global is modified.
56 * @param string $name gettext domain name
57 * @return string gettext domain name
59 function sq_textdomain($domain) {
60 global $gettext_domain;
61 $gettext_domain=textdomain($domain);
62 return $gettext_domain;
66 * php setlocale function wrapper
68 * From php 4.3.0 it is possible to use arrays in order to set locale.
69 * php gettext extension works only when locale is set. This wrapper
70 * function allows to use more than one locale name.
72 * @param int $category locale category name. Use php named constants
73 * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME)
74 * @param mixed $locale option contains array with possible locales or string with one locale
75 * @return string name of set locale or false, if all locales fail.
76 * @since 1.5.1 and 1.4.5
77 * @see http://www.php.net/setlocale
79 function sq_setlocale($category,$locale) {
80 // string with only one locale
81 if (is_string($locale))
82 return setlocale($category,$locale);
84 if (! check_php_version(4,3)) {
87 while ( ! $ret && $index<count($locale)) {
88 $ret=setlocale($category,$locale[$index]);
92 // php 4.3.0 or better, use entire array
93 $ret=setlocale($category,$locale);
99 * Converts string from given charset to charset, that can be displayed by user translation.
101 * Function by default returns html encoded strings, if translation uses different encoding.
102 * If Japanese translation is used - function returns string converted to euc-jp
103 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
104 * If $charset is not supported - function returns unconverted string.
106 * sanitizing of html tags is also done by this function.
108 * @param string $charset
109 * @param string $string Text to be decoded
110 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
111 * Argument is available since 1.5.1 and 1.4.5.
112 * @param boolean $save_html disables htmlspecialchars() in order to preserve
113 * html formating. Use with care. Available since 1.5.1
114 * @return string decoded string
116 function charset_decode ($charset, $string, $force_decode=false, $save_html=false) {
117 global $languages, $squirrelmail_language, $default_charset;
118 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
120 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
121 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
122 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
125 $charset = strtolower($charset);
129 // Variables that allow to use functions without function_exist() calls
130 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
131 $use_php_recode=false; }
132 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
133 $use_php_iconv=false; }
135 // Don't do conversion if charset is the same.
136 if ( ! $force_decode && $charset == strtolower($default_charset) )
137 return ($save_html ?
$string : htmlspecialchars($string));
139 // catch iso-8859-8-i thing
140 if ( $charset == "iso-8859-8-i" )
141 $charset = "iso-8859-8";
144 * Recode converts html special characters automatically if you use
145 * 'charset..html' decoding. There is no documented way to put -d option
146 * into php recode function call.
148 if ( $use_php_recode ) {
149 if ( $default_charset == "utf-8" ) {
150 // other charsets can be converted to utf-8 without loss.
151 // and output string is smaller
152 $string = recode_string($charset . "..utf-8",$string);
153 return ($save_html ?
$string : htmlspecialchars($string));
155 $string = recode_string($charset . "..html",$string);
156 // recode does not convert single quote, htmlspecialchars does.
157 $string = str_replace("'", ''', $string);
158 // undo html specialchars
160 $string=str_replace(array('&','"','<','>'),
161 array('&','"','<','>'),$string);
166 // iconv functions does not have html target and can be used only with utf-8
167 if ( $use_php_iconv && $default_charset=='utf-8') {
168 $string = iconv($charset,$default_charset,$string);
169 return ($save_html ?
$string : htmlspecialchars($string));
172 // If we don't use recode and iconv, we'll do it old way.
174 /* All HTML special characters are 7 bit and can be replaced first */
175 if (! $save_html) $string = htmlspecialchars ($string);
177 /* controls cpu and memory intensive decoding cycles */
178 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
179 $aggressive_decoding=false; }
181 $decode=fixcharset($charset);
182 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
183 if (file_exists($decodefile)) {
184 include_once($decodefile);
185 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
186 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
194 * Converts html string to given charset
195 * @since 1.5.1 and 1.4.4
196 * @param string $string
197 * @param string $charset
198 * @param boolean $htmlencode keep htmlspecialchars encoding
201 function charset_encode($string,$charset,$htmlencode=true) {
202 global $default_charset;
204 $encode=fixcharset($charset);
205 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
206 if (file_exists($encodefile)) {
207 include_once($encodefile);
208 $ret = call_user_func('charset_encode_'.$encode, $string);
209 } elseif(file_exists(SM_PATH
. 'functions/encode/us_ascii.php')) {
210 // function replaces all 8bit html entities with question marks.
211 // it is used when other encoding functions are unavailable
212 include_once(SM_PATH
. 'functions/encode/us_ascii.php');
213 $ret = charset_encode_us_ascii($string);
216 * fix for yahoo users that remove all us-ascii related things
222 * Undo html special chars, some places (like compose form) have
223 * own sanitizing functions and don't need html symbols.
224 * Undo chars only after encoding in order to prevent conversion of
225 * html entities in plain text emails.
227 if (! $htmlencode ) {
228 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
234 * Combined decoding and encoding functions
236 * If conversion is done to charset different that utf-8, unsupported symbols
237 * will be replaced with question marks.
238 * @since 1.5.1 and 1.4.4
239 * @param string $in_charset initial charset
240 * @param string $string string that has to be converted
241 * @param string $out_charset final charset
242 * @param boolean $htmlencode keep htmlspecialchars encoding
243 * @return string converted string
245 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
246 $string=charset_decode($in_charset,$string,true);
247 $string=sqi18n_convert_entities($string);
248 $string=charset_encode($string,$out_charset,$htmlencode);
253 * Makes charset name suitable for decoding cycles
255 * @since 1.5.0 and 1.4.4
256 * @param string $charset Name of charset
257 * @return string $charset Adjusted name of charset
259 function fixcharset($charset) {
260 /* remove minus and characters that might be used in paths from charset
261 * name in order to be able to use it in function names and include calls.
263 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
265 // OE ks_c_5601_1987 > cp949
266 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
267 // Moz x-euc-tw > euc-tw
268 $charset=str_replace('x_euc','euc',$charset);
269 // Moz x-windows-949 > cp949
270 $charset=str_replace('x_windows_','cp',$charset);
272 // windows-125x and cp125x charsets
273 $charset=str_replace('windows_','cp',$charset);
276 $charset=str_replace('ibm','cp',$charset);
278 // iso-8859-8-i -> iso-8859-8
279 // use same cycle until I'll find differences
280 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
286 * Set up the language to be output
287 * if $do_search is true, then scan the browser information
288 * for a possible language that we know
290 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
291 * gettext translation bindings and html header information.
293 * Function returns error codes, if there is some fatal error.
295 * 1 = mbstring support is not present,
296 * 2 = mbstring support is not present, user's translation reverted to en_US.
298 * @param string $sm_language translation used by user's interface
299 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
300 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
301 * @return int function execution error codes.
303 function set_up_language($sm_language, $do_search = false, $default = false) {
305 static $SetupAlready = 0;
306 global $use_gettext, $languages,
307 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
308 $sm_notAlias, $username, $data_dir;
314 $SetupAlready = TRUE;
315 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
318 * If function is asked to detect preferred language
319 * OR squirrelmail default language is set to empty string
321 * squirrelmail language ($sm_language) is empty string
322 * (not set in user's prefs and no cookie with language info)
324 * browser provides list of preferred languages
326 * get preferred language from HTTP_ACCEPT_LANGUAGE header
328 if (($do_search ||
empty($squirrelmail_default_language)) &&
330 isset($accept_lang)) {
331 // TODO: use more than one language, if first language is not available
332 // FIXME: function assumes that string contains two or more characters.
333 // FIXME: some languages use 5 chars
334 $sm_language = substr($accept_lang, 0, 2);
338 * If language preference is not set OR script asks to use default language
340 * default squirrelmail language is not set to empty string
342 * use default squirrelmail language value from configuration.
344 if ((!$sm_language||
$default) &&
345 ! empty($squirrelmail_default_language)) {
346 $squirrelmail_language = $squirrelmail_default_language;
347 $sm_language = $squirrelmail_default_language;
350 /** provide failsafe language when detection fails */
351 if (! $sm_language) $sm_language='en_US';
353 $sm_notAlias = $sm_language;
355 // Catching removed translation
356 // System reverts to English translation if user prefs contain translation
357 // that is not available in $languages array
358 if (!isset($languages[$sm_notAlias])) {
359 $sm_notAlias="en_US";
362 while (isset($languages[$sm_notAlias]['ALIAS'])) {
363 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
366 if ( isset($sm_language) &&
368 $sm_language != '' &&
369 isset($languages[$sm_notAlias]['CHARSET']) ) {
370 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
371 sq_textdomain( 'squirrelmail' );
373 // set codeset in order to avoid gettext charset conversions
374 if (function_exists('bind_textdomain_codeset')) {
375 // Japanese translation uses different internal charset
376 if ($sm_notAlias == 'ja_JP') {
377 bind_textdomain_codeset ('squirrelmail', 'EUC-JP');
379 bind_textdomain_codeset ('squirrelmail', $languages[$sm_notAlias]['CHARSET'] );
383 // Use LOCALE key, if it is set.
384 if (isset($languages[$sm_notAlias]['LOCALE'])){
385 $longlocale=$languages[$sm_notAlias]['LOCALE'];
387 $longlocale=$sm_notAlias;
390 // try setting locale
391 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
393 // check if locale is set and assign that locale to $longlocale
394 // in order to use it in putenv calls.
395 if (! is_bool($retlocale)) {
396 $longlocale=$retlocale;
397 } elseif (is_array($longlocale)) {
398 // setting of all locales failed.
399 // we need string instead of array used in LOCALE key.
400 $longlocale=$sm_notAlias;
403 if ( !((bool)ini_get('safe_mode')) &&
404 getenv( 'LC_ALL' ) != $longlocale ) {
405 putenv( "LC_ALL=$longlocale" );
406 putenv( "LANG=$longlocale" );
407 putenv( "LANGUAGE=$longlocale" );
408 putenv( "LC_NUMERIC=C" );
409 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
411 // Workaround for plugins that use numbers with floating point
412 // It might be removed if plugins use correct decimal delimiters
413 // according to locale settings.
414 setlocale(LC_NUMERIC
, 'C');
415 // Workaround for specific Turkish strtolower/strtoupper rules.
416 // Many functions expect English conversion rules.
417 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
420 * Set text direction/alignment variables
421 * When language environment is setup, scripts can use these globals
422 * without accessing $languages directly and making checks for optional
425 global $text_direction, $left_align, $right_align;
426 if (isset($languages[$sm_notAlias]['DIR']) &&
427 $languages[$sm_notAlias]['DIR'] == 'rtl') {
430 * @global string $text_direction
432 $text_direction='rtl';
435 * @global string $left_align
440 * @global string $right_align
444 $text_direction='ltr';
446 $right_align='right';
449 $squirrelmail_language = $sm_notAlias;
450 if ($squirrelmail_language == 'ja_JP') {
451 header ('Content-Type: text/html; charset=EUC-JP');
452 if (!function_exists('mb_internal_encoding')) {
453 // Error messages can't be displayed here
455 // Revert to English if possible.
456 if (function_exists('setPref') && $username!='' && $data_dir!="") {
457 setPref($data_dir, $username, 'language', "en_US");
460 // stop further execution in order not to get php errors on mb_internal_encoding().
463 if (function_exists('mb_language')) {
464 mb_language('Japanese');
466 mb_internal_encoding('EUC-JP');
467 mb_http_output('pass');
468 } elseif ($squirrelmail_language == 'en_US') {
469 header( 'Content-Type: text/html; charset=' . $default_charset );
471 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
474 * mbstring.func_overload fix (#929644).
476 * php mbstring extension can replace standard string functions with their multibyte
477 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
478 * was added in php v.4.2.0
480 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
481 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
482 * interface can't trust regular string functions. Due to mbstring overloading design
483 * limits php scripts can't control this setting.
485 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
486 * to disable mbstring overloading. Japanese translation uses different internal encoding.
488 if ($squirrelmail_language != 'ja_JP' &&
489 function_exists('mb_internal_encoding') &&
490 check_php_version(4,2,0) &&
491 (int)ini_get('mbstring.func_overload')!=0) {
492 mb_internal_encoding('pass');
499 * Sets default_charset variable according to the one that is used by user's translations.
501 * Function changes global $default_charset variable in order to be sure, that it
502 * contains charset used by user's translation. Sanity of $squirrelmail_language
503 * and $default_charset combination is also tested.
505 * There can be a $default_charset setting in the
506 * config.php file, but the user may have a different language
507 * selected for a user interface. This function checks the
508 * language selected by the user and tags the outgoing messages
509 * with the appropriate charset corresponding to the language
510 * selection. This is "more right" (tm), than just stamping the
511 * message blindly with the system-wide $default_charset.
513 function set_my_charset(){
514 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
516 $my_language = getPref($data_dir, $username, 'language');
518 $my_language = $squirrelmail_language ;
520 // Catch removed translation
521 if (!isset($languages[$my_language])) {
522 $my_language="en_US";
524 while (isset($languages[$my_language]['ALIAS'])) {
525 $my_language = $languages[$my_language]['ALIAS'];
527 $my_charset = $languages[$my_language]['CHARSET'];
528 if ($my_language!='en_US') {
529 $default_charset = $my_charset;
534 * Replaces non-braking spaces inserted by some browsers with regular space
536 * This function can be used to replace non-braking space symbols
537 * that are inserted in forms by some browsers instead of normal
540 * @param string $string Text that needs to be cleaned
541 * @param string $charset Charset used in text
542 * @return string Cleaned text
544 function cleanup_nbsp($string,$charset) {
546 // reduce number of case statements
547 if (stristr('iso-8859-',substr($charset,0,9))){
548 $output_charset="iso-8859-x";
550 if (stristr('windows-125',substr($charset,0,11))){
551 $output_charset="cp125x";
553 if (stristr('koi8',substr($charset,0,4))){
554 $output_charset="koi8-x";
556 if (! isset($output_charset)){
557 $output_charset=strtolower($charset);
560 // where is non-braking space symbol
561 switch($output_charset):
574 // don't change string if charset is unmatched
578 // return space instead of non-braking space.
579 return str_replace($nbsp,' ',$string);
583 * Function informs if it is safe to convert given charset to the one that is used by user.
585 * It is safe to use conversion only if user uses utf-8 encoding and when
586 * converted charset is similar to the one that is used by user.
588 * @param string $input_charset Charset of text that needs to be converted
589 * @return bool is it possible to convert to user's charset
591 function is_conversion_safe($input_charset) {
592 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
594 if (isset($lossy_encoding) && $lossy_encoding )
597 // convert to lower case
598 $input_charset = strtolower($input_charset);
600 // Is user's locale Unicode based ?
601 if ( $default_charset == "utf-8" ) {
605 // Charsets that are similar
606 switch ($default_charset) {
608 if ( $input_charset == "iso-8859-5" ||
609 $input_charset == "koi8-r" ||
610 $input_charset == "koi8-u" ) {
616 if ( $input_charset == "iso-8859-13" ||
617 $input_charset == "iso-8859-4" ) {
623 if ( $input_charset == "iso-8859-13" ||
624 $input_charset == "windows-1257" ) {
630 if ( $input_charset == "windows-1251" ||
631 $input_charset == "koi8-r" ||
632 $input_charset == "koi8-u" ) {
638 if ( $input_charset == "iso-8859-4" ||
639 $input_charset == "windows-1257" ) {
645 if ( $input_charset == "windows-1251" ||
646 $input_charset == "iso-8859-5" ||
647 $input_charset == "koi8-u" ) {
653 if ( $input_charset == "windows-1251" ||
654 $input_charset == "iso-8859-5" ||
655 $input_charset == "koi8-r" ) {
666 * Converts html character entities to numeric entities
668 * SquirrelMail encoding functions work only with numeric entities.
669 * This function fixes issues with decoding functions that might convert
670 * some symbols to character entities. Issue is specific to PHP recode
671 * extension decoding. Function is used internally in charset_convert()
673 * @param string $str string that might contain html character entities
674 * @return string string with character entities converted to decimals.
677 function sqi18n_convert_entities($str) {
681 ' ' => ' ',
682 '¡' => '¡',
683 '¢' => '¢',
684 '£' => '£',
685 '¤' => '¤',
687 '¦' => '¦',
688 '§' => '§',
690 '©' => '©',
691 'ª' => 'ª',
692 '«' => '«',
696 '¯' => '¯',
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 'Ê' => 'Ê',
724 'Ë' => 'Ë',
725 'Ì' => 'Ì',
726 'Í' => 'Í',
727 'Î' => 'Î',
728 'Ï' => 'Ï',
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 'ê' => 'ê',
756 'ë' => 'ë',
757 'ì' => 'ì',
758 'í' => 'í',
759 'î' => 'î',
760 'ï' => 'ï',
762 'ñ' => 'ñ',
763 'ò' => 'ò',
764 'ó' => 'ó',
765 'ô' => 'ô',
766 'õ' => 'õ',
767 'ö' => 'ö',
768 '÷' => '÷',
769 'ø' => 'ø',
770 'ù' => 'ù',
771 'ú' => 'ú',
772 'û' => 'û',
773 'ü' => 'ü',
774 'ý' => 'ý',
775 'þ' => 'þ',
776 'ÿ' => 'ÿ',
778 'Œ' => 'Œ',
779 'œ' => 'œ',
780 'Š' => 'Š',
781 'š' => 'š',
782 'Ÿ' => 'Ÿ',
783 // Spacing Modifier Letters
784 'ˆ' => 'ˆ',
785 '˜' => '˜',
786 // General Punctuation
787 ' ' => ' ',
788 ' ' => ' ',
789 ' ' => ' ',
790 '‌' => '‌',
791 '‍' => '‍',
792 '‎' => '‎',
793 '‏' => '‏',
794 '–' => '–',
795 '—' => '—',
796 '‘' => '‘',
797 '’' => '’',
798 '‚' => '‚',
799 '“' => '“',
800 '”' => '”',
801 '„' => '„',
802 '†' => '†',
803 '‡' => '‡',
804 '‰' => '‰',
805 '‹' => '‹',
806 '›' => '›',
807 '€' => '€',
809 'ƒ' => 'ƒ',
811 'Α' => 'Α',
812 'Β' => 'Β',
813 'Γ' => 'Γ',
814 'Δ' => 'Δ',
815 'Ε' => 'Ε',
816 'Ζ' => 'Ζ',
818 'Θ' => 'Θ',
819 'Ι' => 'Ι',
820 'Κ' => 'Κ',
821 'Λ' => 'Λ',
825 'Ο' => 'Ο',
828 'Σ' => 'Σ',
830 'Υ' => 'Υ',
834 'Ω' => 'Ω',
835 'α' => 'α',
836 'β' => 'β',
837 'γ' => 'γ',
838 'δ' => 'δ',
839 'ε' => 'ε',
840 'ζ' => 'ζ',
842 'θ' => 'θ',
843 'ι' => 'ι',
844 'κ' => 'κ',
845 'λ' => 'λ',
849 'ο' => 'ο',
852 'ς' => 'ς',
853 'σ' => 'σ',
855 'υ' => 'υ',
859 'ω' => 'ω',
860 'ϑ' => 'ϑ',
861 'ϒ' => 'ϒ',
863 // General Punctuation
864 '•' => '•',
865 '…' => '…',
866 '′' => '′',
867 '″' => '″',
868 '‾' => '‾',
869 '⁄' => '⁄',
870 // Letterlike Symbols
871 '℘' => '℘',
872 'ℑ' => 'ℑ',
873 'ℜ' => 'ℜ',
874 '™' => '™',
875 'ℵ' => 'ℵ',
877 '←' => '←',
878 '↑' => '↑',
879 '→' => '→',
880 '↓' => '↓',
881 '↔' => '↔',
882 '↵' => '↵',
883 '⇐' => '⇐',
884 '⇑' => '⇑',
885 '⇒' => '⇒',
886 '⇓' => '⇓',
887 '⇔' => '⇔',
888 // Mathematical Operators
889 '∀' => '∀',
890 '∂' => '∂',
891 '∃' => '∃',
892 '∅' => '∅',
893 '∇' => '∇',
894 '∈' => '∈',
895 '∉' => '∉',
897 '∏' => '∏',
898 '∑' => '∑',
899 '−' => '−',
900 '∗' => '∗',
901 '√' => '√',
902 '∝' => '∝',
903 '∞' => '∞',
904 '∠' => '∠',
905 '∧' => '∧',
907 '∩' => '∩',
908 '∪' => '∪',
909 '∫' => '∫',
910 '∴' => '∴',
911 '∼' => '∼',
912 '≅' => '≅',
913 '≈' => '≈',
915 '≡' => '≡',
918 '⊂' => '⊂',
919 '⊃' => '⊃',
920 '⊄' => '⊄',
921 '⊆' => '⊆',
922 '⊇' => '⊇',
923 '⊕' => '⊕',
924 '⊗' => '⊗',
925 '⊥' => '⊥',
926 '⋅' => '⋅',
927 // Miscellaneous Technical
928 '⌈' => '⌈',
929 '⌉' => '⌉',
930 '⌊' => '⌊',
931 '⌋' => '⌋',
932 '⟨' => '〈',
933 '⟩' => '〉',
935 '◊' => '◊',
936 // Miscellaneous Symbols
937 '♠' => '♠',
938 '♣' => '♣',
939 '♥' => '♥',
940 '♦' => '♦');
942 $str = str_replace(array_keys($entities), array_values($entities), $str);
947 /* ------------------------------ main --------------------------- */
949 global $squirrelmail_language, $languages, $use_gettext;
951 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
952 $squirrelmail_language = '';
956 * Array specifies the available translations.
958 * Structure of array:
959 * $languages['language']['variable'] = 'value'
961 * Possible 'variable' names:
962 * NAME - Translation name in English
963 * CHARSET - Encoding used by translation
964 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
965 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
966 * 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
967 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
968 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
970 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
973 * @global array $languages
975 $languages['en_US']['NAME'] = 'English';
976 $languages['en_US']['CHARSET'] = 'iso-8859-1';
977 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
978 $languages['en']['ALIAS'] = 'en_US';
981 * Automatic translation loading from setup.php files.
982 * Solution for bug. 1240889.
983 * setup.php file can contain $languages array entries and XTRA_CODE functions.
985 if (is_dir(SM_PATH
. 'locale') &&
986 is_readable(SM_PATH
. 'locale')) {
987 $localedir = dir(SM_PATH
. 'locale');
988 while($lang_dir=$localedir->read()) {
989 // remove trailing slash, if present
990 if (substr($lang_dir,-1)=='/') {
991 $lang_dir = substr($lang_dir,0,-1);
993 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
994 is_dir(SM_PATH
.'locale/'.$lang_dir) &&
995 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
996 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1002 /* Detect whether gettext is installed. */
1004 if (function_exists('_')) {
1005 $gettext_flags +
= 1;
1007 if (function_exists('bindtextdomain')) {
1008 $gettext_flags +
= 2;
1010 if (function_exists('textdomain')) {
1011 $gettext_flags +
= 4;
1013 if (function_exists('ngettext')) {
1014 $gettext_flags +
= 8;
1017 /* If gettext is fully loaded, cool */
1018 if ($gettext_flags == 15) {
1019 $use_gettext = true;
1022 /* If ngettext support is missing, load it */
1023 elseif ($gettext_flags == 7) {
1024 $use_gettext = true;
1025 // load internal ngettext functions
1026 include_once(SM_PATH
. 'class/l10n.class.php');
1027 include_once(SM_PATH
. 'functions/ngettext.php');
1030 /* If we can fake gettext, try that */
1031 elseif ($gettext_flags == 0) {
1032 $use_gettext = true;
1033 include_once(SM_PATH
. 'functions/gettext.php');
1035 /* Uh-ho. A weird install */
1036 if (! $gettext_flags & 1) {
1038 * Function is used as replacement in broken installs
1045 if (! $gettext_flags & 2) {
1047 * Function is used as replacement in broken installs
1050 function bindtextdomain() {
1054 if (! $gettext_flags & 4) {
1056 * Function is used as replacemet in broken installs
1059 function textdomain() {
1063 if (! $gettext_flags & 8) {
1065 * Function is used as replacemet in broken installs
1068 function ngettext($str,$str2,$number) {
1076 if (! function_exists('dgettext')) {
1078 * Replacement for broken setups.
1081 function dgettext($domain,$str) {
1085 if (! function_exists('dngettext')) {
1087 * Replacement for broken setups
1090 function dngettext($domain,$str1,$strn,$number) {
1091 return ($number==1 ?
$str1 : $strn);