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 * Before 1.5.2 functions were stored in functions/i18n.php. Script is moved
13 * because it executes some code in order to detect functions supported by
14 * existing PHP installation and implements fallback functions when required
15 * functions are not available. Scripts in functions/ directory should not
16 * setup anything when they are loaded.
17 * @copyright © 1999-2006 The SquirrelMail Project Team
18 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
20 * @package squirrelmail
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 if (is_string($locale)) {
81 // string with only one locale
82 $ret = setlocale($category,$locale);
83 } elseif (! check_php_version(4,3)) {
84 // older php version (second setlocale argument must be string)
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);
97 if (preg_match("/^.*\/.*\/.*\/.*\/.*\/.*$/",$ret)) {
99 * Welcome to We-Don't-Follow-Own-Fine-Manual department
100 * OpenBSD 3.8, 3.9-current and maybe later versions
101 * return invalid response to setlocale command.
102 * SM bug report #1427512.
110 * Converts string from given charset to charset, that can be displayed by user translation.
112 * Function by default returns html encoded strings, if translation uses different encoding.
113 * If Japanese translation is used - function returns string converted to euc-jp
114 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
115 * If $charset is not supported - function returns unconverted string.
117 * sanitizing of html tags is also done by this function.
119 * @param string $charset
120 * @param string $string Text to be decoded
121 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
122 * Argument is available since 1.5.1 and 1.4.5.
123 * @param boolean $save_html disables htmlspecialchars() in order to preserve
124 * html formating. Use with care. Available since 1.5.1
125 * @return string decoded string
127 function charset_decode ($charset, $string, $force_decode=false, $save_html=false) {
128 global $languages, $squirrelmail_language, $default_charset;
129 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
131 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
132 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
133 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
136 $charset = strtolower($charset);
140 // Variables that allow to use functions without function_exist() calls
141 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
142 $use_php_recode=false; }
143 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
144 $use_php_iconv=false; }
146 // Don't do conversion if charset is the same.
147 if ( ! $force_decode && $charset == strtolower($default_charset) )
148 return ($save_html ?
$string : htmlspecialchars($string));
150 // catch iso-8859-8-i thing
151 if ( $charset == "iso-8859-8-i" )
152 $charset = "iso-8859-8";
155 * Recode converts html special characters automatically if you use
156 * 'charset..html' decoding. There is no documented way to put -d option
157 * into php recode function call.
159 if ( $use_php_recode ) {
160 if ( $default_charset == "utf-8" ) {
161 // other charsets can be converted to utf-8 without loss.
162 // and output string is smaller
163 $string = recode_string($charset . "..utf-8",$string);
164 return ($save_html ?
$string : htmlspecialchars($string));
166 $string = recode_string($charset . "..html",$string);
167 // recode does not convert single quote, htmlspecialchars does.
168 $string = str_replace("'", ''', $string);
169 // undo html specialchars
171 $string=str_replace(array('&','"','<','>'),
172 array('&','"','<','>'),$string);
177 // iconv functions does not have html target and can be used only with utf-8
178 if ( $use_php_iconv && $default_charset=='utf-8') {
179 $string = iconv($charset,$default_charset,$string);
180 return ($save_html ?
$string : htmlspecialchars($string));
183 // If we don't use recode and iconv, we'll do it old way.
185 /* All HTML special characters are 7 bit and can be replaced first */
186 if (! $save_html) $string = htmlspecialchars ($string);
188 /* controls cpu and memory intensive decoding cycles */
189 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
190 $aggressive_decoding=false; }
192 $decode=fixcharset($charset);
193 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
194 if (file_exists($decodefile)) {
195 include_once($decodefile);
196 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
197 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
205 * Converts html string to given charset
206 * @since 1.5.1 and 1.4.4
207 * @param string $string
208 * @param string $charset
209 * @param boolean $htmlencode keep htmlspecialchars encoding
212 function charset_encode($string,$charset,$htmlencode=true) {
213 global $default_charset;
215 $encode=fixcharset($charset);
216 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
217 if (file_exists($encodefile)) {
218 include_once($encodefile);
219 $ret = call_user_func('charset_encode_'.$encode, $string);
220 } elseif(file_exists(SM_PATH
. 'functions/encode/us_ascii.php')) {
221 // function replaces all 8bit html entities with question marks.
222 // it is used when other encoding functions are unavailable
223 include_once(SM_PATH
. 'functions/encode/us_ascii.php');
224 $ret = charset_encode_us_ascii($string);
227 * fix for yahoo users that remove all us-ascii related things
233 * Undo html special chars, some places (like compose form) have
234 * own sanitizing functions and don't need html symbols.
235 * Undo chars only after encoding in order to prevent conversion of
236 * html entities in plain text emails.
238 if (! $htmlencode ) {
239 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
245 * Combined decoding and encoding functions
247 * If conversion is done to charset different that utf-8, unsupported symbols
248 * will be replaced with question marks.
249 * @since 1.5.1 and 1.4.4
250 * @param string $in_charset initial charset
251 * @param string $string string that has to be converted
252 * @param string $out_charset final charset
253 * @param boolean $htmlencode keep htmlspecialchars encoding
254 * @return string converted string
256 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
257 $string=charset_decode($in_charset,$string,true);
258 $string=sqi18n_convert_entities($string);
259 $string=charset_encode($string,$out_charset,$htmlencode);
264 * Makes charset name suitable for decoding cycles
266 * @since 1.5.0 and 1.4.4
267 * @param string $charset Name of charset
268 * @return string $charset Adjusted name of charset
270 function fixcharset($charset) {
271 /* remove minus and characters that might be used in paths from charset
272 * name in order to be able to use it in function names and include calls.
274 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
276 // OE ks_c_5601_1987 > cp949
277 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
278 // Moz x-euc-tw > euc-tw
279 $charset=str_replace('x_euc','euc',$charset);
280 // Moz x-windows-949 > cp949
281 $charset=str_replace('x_windows_','cp',$charset);
283 // windows-125x and cp125x charsets
284 $charset=str_replace('windows_','cp',$charset);
287 $charset=str_replace('ibm','cp',$charset);
289 // iso-8859-8-i -> iso-8859-8
290 // use same cycle until I'll find differences
291 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
297 * Set up the language to be output
298 * if $do_search is true, then scan the browser information
299 * for a possible language that we know
301 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
302 * gettext translation bindings and html header information.
304 * Function returns error codes, if there is some fatal error.
306 * 1 = mbstring support is not present,
307 * 2 = mbstring support is not present, user's translation reverted to en_US.
309 * @param string $sm_language translation used by user's interface
310 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
311 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
312 * @return int function execution error codes.
314 function set_up_language($sm_language, $do_search = false, $default = false) {
316 static $SetupAlready = 0;
317 global $use_gettext, $languages,
318 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
319 $sm_notAlias, $username, $data_dir;
325 $SetupAlready = TRUE;
326 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
329 * If function is asked to detect preferred language
330 * OR squirrelmail default language is set to empty string
332 * squirrelmail language ($sm_language) is empty string
333 * (not set in user's prefs and no cookie with language info)
335 * browser provides list of preferred languages
337 * get preferred language from HTTP_ACCEPT_LANGUAGE header
339 if (($do_search ||
empty($squirrelmail_default_language)) &&
341 isset($accept_lang)) {
342 // TODO: use more than one language, if first language is not available
343 // FIXME: function assumes that string contains two or more characters.
344 // FIXME: some languages use 5 chars
345 $sm_language = substr($accept_lang, 0, 2);
349 * If language preference is not set OR script asks to use default language
351 * default squirrelmail language is not set to empty string
353 * use default squirrelmail language value from configuration.
355 if ((!$sm_language||
$default) &&
356 ! empty($squirrelmail_default_language)) {
357 $squirrelmail_language = $squirrelmail_default_language;
358 $sm_language = $squirrelmail_default_language;
361 /** provide failsafe language when detection fails */
362 if (! $sm_language) $sm_language='en_US';
364 $sm_notAlias = $sm_language;
366 // Catching removed translation
367 // System reverts to English translation if user prefs contain translation
368 // that is not available in $languages array
369 if (!isset($languages[$sm_notAlias])) {
370 $sm_notAlias="en_US";
373 while (isset($languages[$sm_notAlias]['ALIAS'])) {
374 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
377 if ( isset($sm_language) &&
379 $sm_language != '' &&
380 isset($languages[$sm_notAlias]['CHARSET']) ) {
381 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
382 sq_textdomain( 'squirrelmail' );
384 // set codeset in order to avoid gettext charset conversions
385 if (function_exists('bind_textdomain_codeset')) {
386 // Japanese translation uses different internal charset
387 if ($sm_notAlias == 'ja_JP') {
388 bind_textdomain_codeset ('squirrelmail', 'EUC-JP');
390 bind_textdomain_codeset ('squirrelmail', $languages[$sm_notAlias]['CHARSET'] );
394 // Use LOCALE key, if it is set.
395 if (isset($languages[$sm_notAlias]['LOCALE'])){
396 $longlocale=$languages[$sm_notAlias]['LOCALE'];
398 $longlocale=$sm_notAlias;
401 // try setting locale
402 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
404 // check if locale is set and assign that locale to $longlocale
405 // in order to use it in putenv calls.
406 if (! is_bool($retlocale)) {
407 $longlocale=$retlocale;
408 } elseif (is_array($longlocale)) {
409 // setting of all locales failed.
410 // we need string instead of array used in LOCALE key.
411 $longlocale=$sm_notAlias;
414 if ( !((bool)ini_get('safe_mode')) &&
415 getenv( 'LC_ALL' ) != $longlocale ) {
416 putenv( "LC_ALL=$longlocale" );
417 putenv( "LANG=$longlocale" );
418 putenv( "LANGUAGE=$longlocale" );
419 putenv( "LC_NUMERIC=C" );
420 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
422 // Workaround for plugins that use numbers with floating point
423 // It might be removed if plugins use correct decimal delimiters
424 // according to locale settings.
425 setlocale(LC_NUMERIC
, 'C');
426 // Workaround for specific Turkish strtolower/strtoupper rules.
427 // Many functions expect English conversion rules.
428 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
431 * Set text direction/alignment variables
432 * When language environment is setup, scripts can use these globals
433 * without accessing $languages directly and making checks for optional
436 global $text_direction, $left_align, $right_align;
437 if (isset($languages[$sm_notAlias]['DIR']) &&
438 $languages[$sm_notAlias]['DIR'] == 'rtl') {
441 * @global string $text_direction
443 $text_direction='rtl';
446 * @global string $left_align
451 * @global string $right_align
455 $text_direction='ltr';
457 $right_align='right';
460 $squirrelmail_language = $sm_notAlias;
461 if ($squirrelmail_language == 'ja_JP') {
462 header ('Content-Type: text/html; charset=EUC-JP');
463 if (!function_exists('mb_internal_encoding')) {
464 // Error messages can't be displayed here
466 // Revert to English if possible.
467 if (function_exists('setPref') && $username!='' && $data_dir!="") {
468 setPref($data_dir, $username, 'language', "en_US");
471 // stop further execution in order not to get php errors on mb_internal_encoding().
474 if (function_exists('mb_language')) {
475 mb_language('Japanese');
477 mb_internal_encoding('EUC-JP');
478 mb_http_output('pass');
479 } elseif ($squirrelmail_language == 'en_US') {
480 header( 'Content-Type: text/html; charset=' . $default_charset );
482 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
485 * mbstring.func_overload fix (#929644).
487 * php mbstring extension can replace standard string functions with their multibyte
488 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
489 * was added in php v.4.2.0
491 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
492 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
493 * interface can't trust regular string functions. Due to mbstring overloading design
494 * limits php scripts can't control this setting.
496 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
497 * to disable mbstring overloading. Japanese translation uses different internal encoding.
499 if ($squirrelmail_language != 'ja_JP' &&
500 function_exists('mb_internal_encoding') &&
501 check_php_version(4,2,0) &&
502 (int)ini_get('mbstring.func_overload')!=0) {
503 mb_internal_encoding('pass');
510 * Sets default_charset variable according to the one that is used by user's translations.
512 * Function changes global $default_charset variable in order to be sure, that it
513 * contains charset used by user's translation. Sanity of $squirrelmail_language
514 * and $default_charset combination is also tested.
516 * There can be a $default_charset setting in the
517 * config.php file, but the user may have a different language
518 * selected for a user interface. This function checks the
519 * language selected by the user and tags the outgoing messages
520 * with the appropriate charset corresponding to the language
521 * selection. This is "more right" (tm), than just stamping the
522 * message blindly with the system-wide $default_charset.
524 function set_my_charset(){
525 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
527 $my_language = getPref($data_dir, $username, 'language');
529 $my_language = $squirrelmail_language ;
531 // Catch removed translation
532 if (!isset($languages[$my_language])) {
533 $my_language="en_US";
535 while (isset($languages[$my_language]['ALIAS'])) {
536 $my_language = $languages[$my_language]['ALIAS'];
538 $my_charset = $languages[$my_language]['CHARSET'];
539 if ($my_language!='en_US') {
540 $default_charset = $my_charset;
545 * Replaces non-braking spaces inserted by some browsers with regular space
547 * This function can be used to replace non-braking space symbols
548 * that are inserted in forms by some browsers instead of normal
551 * @param string $string Text that needs to be cleaned
552 * @param string $charset Charset used in text
553 * @return string Cleaned text
555 function cleanup_nbsp($string,$charset) {
557 // reduce number of case statements
558 if (stristr('iso-8859-',substr($charset,0,9))){
559 $output_charset="iso-8859-x";
561 if (stristr('windows-125',substr($charset,0,11))){
562 $output_charset="cp125x";
564 if (stristr('koi8',substr($charset,0,4))){
565 $output_charset="koi8-x";
567 if (! isset($output_charset)){
568 $output_charset=strtolower($charset);
571 // where is non-braking space symbol
572 switch($output_charset):
585 // don't change string if charset is unmatched
589 // return space instead of non-braking space.
590 return str_replace($nbsp,' ',$string);
594 * Function informs if it is safe to convert given charset to the one that is used by user.
596 * It is safe to use conversion only if user uses utf-8 encoding and when
597 * converted charset is similar to the one that is used by user.
599 * @param string $input_charset Charset of text that needs to be converted
600 * @return bool is it possible to convert to user's charset
602 function is_conversion_safe($input_charset) {
603 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
605 if (isset($lossy_encoding) && $lossy_encoding )
608 // convert to lower case
609 $input_charset = strtolower($input_charset);
611 // Is user's locale Unicode based ?
612 if ( $default_charset == "utf-8" ) {
616 // Charsets that are similar
617 switch ($default_charset) {
619 if ( $input_charset == "iso-8859-5" ||
620 $input_charset == "koi8-r" ||
621 $input_charset == "koi8-u" ) {
627 if ( $input_charset == "iso-8859-13" ||
628 $input_charset == "iso-8859-4" ) {
634 if ( $input_charset == "iso-8859-13" ||
635 $input_charset == "windows-1257" ) {
641 if ( $input_charset == "windows-1251" ||
642 $input_charset == "koi8-r" ||
643 $input_charset == "koi8-u" ) {
649 if ( $input_charset == "iso-8859-4" ||
650 $input_charset == "windows-1257" ) {
656 if ( $input_charset == "windows-1251" ||
657 $input_charset == "iso-8859-5" ||
658 $input_charset == "koi8-u" ) {
664 if ( $input_charset == "windows-1251" ||
665 $input_charset == "iso-8859-5" ||
666 $input_charset == "koi8-r" ) {
677 * Converts html character entities to numeric entities
679 * SquirrelMail encoding functions work only with numeric entities.
680 * This function fixes issues with decoding functions that might convert
681 * some symbols to character entities. Issue is specific to PHP recode
682 * extension decoding. Function is used internally in charset_convert()
684 * @param string $str string that might contain html character entities
685 * @return string string with character entities converted to decimals.
688 function sqi18n_convert_entities($str) {
692 ' ' => ' ',
693 '¡' => '¡',
694 '¢' => '¢',
695 '£' => '£',
696 '¤' => '¤',
698 '¦' => '¦',
699 '§' => '§',
701 '©' => '©',
702 'ª' => 'ª',
703 '«' => '«',
707 '¯' => '¯',
709 '±' => '±',
710 '²' => '²',
711 '³' => '³',
712 '´' => '´',
713 'µ' => 'µ',
714 '¶' => '¶',
715 '·' => '·',
716 '¸' => '¸',
717 '¹' => '¹',
718 'º' => 'º',
719 '»' => '»',
720 '¼' => '¼',
721 '½' => '½',
722 '¾' => '¾',
723 '¿' => '¿',
724 'À' => 'À',
725 'Á' => 'Á',
726 'Â' => 'Â',
727 'Ã' => 'Ã',
728 'Ä' => 'Ä',
729 'Å' => 'Å',
730 'Æ' => 'Æ',
731 'Ç' => 'Ç',
732 'È' => 'È',
733 'É' => 'É',
734 'Ê' => 'Ê',
735 'Ë' => 'Ë',
736 'Ì' => 'Ì',
737 'Í' => 'Í',
738 'Î' => 'Î',
739 'Ï' => 'Ï',
741 'Ñ' => 'Ñ',
742 'Ò' => 'Ò',
743 'Ó' => 'Ó',
744 'Ô' => 'Ô',
745 'Õ' => 'Õ',
746 'Ö' => 'Ö',
747 '×' => '×',
748 'Ø' => 'Ø',
749 'Ù' => 'Ù',
750 'Ú' => 'Ú',
751 'Û' => 'Û',
752 'Ü' => 'Ü',
753 'Ý' => 'Ý',
754 'Þ' => 'Þ',
755 'ß' => 'ß',
756 'à' => 'à',
757 'á' => 'á',
758 'â' => 'â',
759 'ã' => 'ã',
760 'ä' => 'ä',
761 'å' => 'å',
762 'æ' => 'æ',
763 'ç' => 'ç',
764 'è' => 'è',
765 'é' => 'é',
766 'ê' => 'ê',
767 'ë' => 'ë',
768 'ì' => 'ì',
769 'í' => 'í',
770 'î' => 'î',
771 'ï' => 'ï',
773 'ñ' => 'ñ',
774 'ò' => 'ò',
775 'ó' => 'ó',
776 'ô' => 'ô',
777 'õ' => 'õ',
778 'ö' => 'ö',
779 '÷' => '÷',
780 'ø' => 'ø',
781 'ù' => 'ù',
782 'ú' => 'ú',
783 'û' => 'û',
784 'ü' => 'ü',
785 'ý' => 'ý',
786 'þ' => 'þ',
787 'ÿ' => 'ÿ',
789 'Œ' => 'Œ',
790 'œ' => 'œ',
791 'Š' => 'Š',
792 'š' => 'š',
793 'Ÿ' => 'Ÿ',
794 // Spacing Modifier Letters
795 'ˆ' => 'ˆ',
796 '˜' => '˜',
797 // General Punctuation
798 ' ' => ' ',
799 ' ' => ' ',
800 ' ' => ' ',
801 '‌' => '‌',
802 '‍' => '‍',
803 '‎' => '‎',
804 '‏' => '‏',
805 '–' => '–',
806 '—' => '—',
807 '‘' => '‘',
808 '’' => '’',
809 '‚' => '‚',
810 '“' => '“',
811 '”' => '”',
812 '„' => '„',
813 '†' => '†',
814 '‡' => '‡',
815 '‰' => '‰',
816 '‹' => '‹',
817 '›' => '›',
818 '€' => '€',
820 'ƒ' => 'ƒ',
822 'Α' => 'Α',
823 'Β' => 'Β',
824 'Γ' => 'Γ',
825 'Δ' => 'Δ',
826 'Ε' => 'Ε',
827 'Ζ' => 'Ζ',
829 'Θ' => 'Θ',
830 'Ι' => 'Ι',
831 'Κ' => 'Κ',
832 'Λ' => 'Λ',
836 'Ο' => 'Ο',
839 'Σ' => 'Σ',
841 'Υ' => 'Υ',
845 'Ω' => 'Ω',
846 'α' => 'α',
847 'β' => 'β',
848 'γ' => 'γ',
849 'δ' => 'δ',
850 'ε' => 'ε',
851 'ζ' => 'ζ',
853 'θ' => 'θ',
854 'ι' => 'ι',
855 'κ' => 'κ',
856 'λ' => 'λ',
860 'ο' => 'ο',
863 'ς' => 'ς',
864 'σ' => 'σ',
866 'υ' => 'υ',
870 'ω' => 'ω',
871 'ϑ' => 'ϑ',
872 'ϒ' => 'ϒ',
874 // General Punctuation
875 '•' => '•',
876 '…' => '…',
877 '′' => '′',
878 '″' => '″',
879 '‾' => '‾',
880 '⁄' => '⁄',
881 // Letterlike Symbols
882 '℘' => '℘',
883 'ℑ' => 'ℑ',
884 'ℜ' => 'ℜ',
885 '™' => '™',
886 'ℵ' => 'ℵ',
888 '←' => '←',
889 '↑' => '↑',
890 '→' => '→',
891 '↓' => '↓',
892 '↔' => '↔',
893 '↵' => '↵',
894 '⇐' => '⇐',
895 '⇑' => '⇑',
896 '⇒' => '⇒',
897 '⇓' => '⇓',
898 '⇔' => '⇔',
899 // Mathematical Operators
900 '∀' => '∀',
901 '∂' => '∂',
902 '∃' => '∃',
903 '∅' => '∅',
904 '∇' => '∇',
905 '∈' => '∈',
906 '∉' => '∉',
908 '∏' => '∏',
909 '∑' => '∑',
910 '−' => '−',
911 '∗' => '∗',
912 '√' => '√',
913 '∝' => '∝',
914 '∞' => '∞',
915 '∠' => '∠',
916 '∧' => '∧',
918 '∩' => '∩',
919 '∪' => '∪',
920 '∫' => '∫',
921 '∴' => '∴',
922 '∼' => '∼',
923 '≅' => '≅',
924 '≈' => '≈',
926 '≡' => '≡',
929 '⊂' => '⊂',
930 '⊃' => '⊃',
931 '⊄' => '⊄',
932 '⊆' => '⊆',
933 '⊇' => '⊇',
934 '⊕' => '⊕',
935 '⊗' => '⊗',
936 '⊥' => '⊥',
937 '⋅' => '⋅',
938 // Miscellaneous Technical
939 '⌈' => '⌈',
940 '⌉' => '⌉',
941 '⌊' => '⌊',
942 '⌋' => '⌋',
943 '⟨' => '〈',
944 '⟩' => '〉',
946 '◊' => '◊',
947 // Miscellaneous Symbols
948 '♠' => '♠',
949 '♣' => '♣',
950 '♥' => '♥',
951 '♦' => '♦');
953 $str = str_replace(array_keys($entities), array_values($entities), $str);
958 /* ------------------------------ main --------------------------- */
960 global $squirrelmail_language, $languages, $use_gettext;
962 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
963 $squirrelmail_language = '';
967 * Array specifies the available translations.
969 * Structure of array:
970 * $languages['language']['variable'] = 'value'
972 * Possible 'variable' names:
973 * NAME - Translation name in English
974 * CHARSET - Encoding used by translation
975 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
976 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
977 * 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
978 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
979 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
981 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
984 * @global array $languages
986 $languages['en_US']['NAME'] = 'English';
987 $languages['en_US']['CHARSET'] = 'iso-8859-1';
988 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
989 $languages['en']['ALIAS'] = 'en_US';
992 * Automatic translation loading from setup.php files.
993 * Solution for bug. 1240889.
994 * setup.php file can contain $languages array entries and XTRA_CODE functions.
996 if (is_dir(SM_PATH
. 'locale') &&
997 is_readable(SM_PATH
. 'locale')) {
998 $localedir = dir(SM_PATH
. 'locale');
999 while($lang_dir=$localedir->read()) {
1000 // remove trailing slash, if present
1001 if (substr($lang_dir,-1)=='/') {
1002 $lang_dir = substr($lang_dir,0,-1);
1004 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
1005 is_dir(SM_PATH
.'locale/'.$lang_dir) &&
1006 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
1007 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1010 $localedir->close();
1013 /* Detect whether gettext is installed. */
1015 if (function_exists('_')) {
1016 $gettext_flags +
= 1;
1018 if (function_exists('bindtextdomain')) {
1019 $gettext_flags +
= 2;
1021 if (function_exists('textdomain')) {
1022 $gettext_flags +
= 4;
1024 if (function_exists('ngettext')) {
1025 $gettext_flags +
= 8;
1028 /* If gettext is fully loaded, cool */
1029 if ($gettext_flags == 15) {
1030 $use_gettext = true;
1033 /* If ngettext support is missing, load it */
1034 elseif ($gettext_flags == 7) {
1035 $use_gettext = true;
1036 // load internal ngettext functions
1037 include_once(SM_PATH
. 'class/l10n.class.php');
1038 include_once(SM_PATH
. 'functions/ngettext.php');
1041 /* If we can fake gettext, try that */
1042 elseif ($gettext_flags == 0) {
1043 $use_gettext = true;
1044 include_once(SM_PATH
. 'functions/gettext.php');
1046 /* Uh-ho. A weird install */
1047 if (! $gettext_flags & 1) {
1049 * Function is used as replacement in broken installs
1056 if (! $gettext_flags & 2) {
1058 * Function is used as replacement in broken installs
1061 function bindtextdomain() {
1065 if (! $gettext_flags & 4) {
1067 * Function is used as replacemet in broken installs
1070 function textdomain() {
1074 if (! $gettext_flags & 8) {
1076 * Function is used as replacemet in broken installs
1079 function ngettext($str,$str2,$number) {
1087 if (! function_exists('dgettext')) {
1089 * Replacement for broken setups.
1092 function dgettext($domain,$str) {
1096 if (! function_exists('dngettext')) {
1098 * Replacement for broken setups
1101 function dngettext($domain,$str1,$strn,$number) {
1102 return ($number==1 ?
$str1 : $strn);