97eeb095a30b69ca575e2100e28605b39c3c7af2
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 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)
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);
92 if (preg_match("/^.*\/.*\/.*\/.*\/.*\/.*$/",$ret)) {
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.
105 * Converts string from given charset to charset, that can be displayed by user translation.
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.
112 * sanitizing of html tags is also done by this function.
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
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;
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);
131 $charset = strtolower($charset);
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; }
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));
145 // catch iso-8859-8-i thing
146 if ( $charset == "iso-8859-8-i" )
147 $charset = "iso-8859-8";
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.
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));
161 $string = recode_string($charset . "..html",$string);
162 // recode does not convert single quote, htmlspecialchars does.
163 $string = str_replace("'", ''', $string);
164 // undo html specialchars
166 $string=str_replace(array('&','"','<','>'),
167 array('&','"','<','>'),$string);
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));
178 // If we don't use recode and iconv, we'll do it old way.
180 /* All HTML special characters are 7 bit and can be replaced first */
181 if (! $save_html) $string = htmlspecialchars ($string);
183 /* controls cpu and memory intensive decoding cycles */
184 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
185 $aggressive_decoding=false; }
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);
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
207 function charset_encode($string,$charset,$htmlencode=true) {
208 global $default_charset;
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);
222 * fix for yahoo users that remove all us-ascii related things
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.
233 if (! $htmlencode ) {
234 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
240 * Combined decoding and encoding functions
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
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);
259 * Makes charset name suitable for decoding cycles
261 * @since 1.5.0 and 1.4.4
262 * @param string $charset Name of charset
263 * @return string $charset Adjusted name of charset
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.
269 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
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);
278 // windows-125x and cp125x charsets
279 $charset=str_replace('windows_','cp',$charset);
282 $charset=str_replace('ibm','cp',$charset);
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);
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
296 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
297 * gettext translation bindings and html header information.
299 * Function returns error codes, if there is some fatal error.
301 * 1 = mbstring support is not present,
302 * 2 = mbstring support is not present, user's translation reverted to en_US.
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.
309 function set_up_language($sm_language, $do_search = false, $default = false) {
311 static $SetupAlready = 0;
312 global $use_gettext, $languages,
313 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
314 $sm_notAlias, $username, $data_dir;
320 $SetupAlready = TRUE;
321 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
324 * If function is asked to detect preferred language
325 * OR squirrelmail default language is set to empty string
327 * squirrelmail language ($sm_language) is empty string
328 * (not set in user's prefs and no cookie with language info)
330 * browser provides list of preferred languages
332 * get preferred language from HTTP_ACCEPT_LANGUAGE header
334 if (($do_search ||
empty($squirrelmail_default_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);
344 * If language preference is not set OR script asks to use default language
346 * default squirrelmail language is not set to empty string
348 * use default squirrelmail language value from configuration.
350 if ((!$sm_language||
$default) &&
351 ! empty($squirrelmail_default_language)) {
352 $squirrelmail_language = $squirrelmail_default_language;
353 $sm_language = $squirrelmail_default_language;
356 /** provide failsafe language when detection fails */
357 if (! $sm_language) $sm_language='en_US';
359 $sm_notAlias = $sm_language;
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";
368 while (isset($languages[$sm_notAlias]['ALIAS'])) {
369 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
372 if ( isset($sm_language) &&
374 $sm_language != '' &&
375 isset($languages[$sm_notAlias]['CHARSET']) ) {
376 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
377 sq_textdomain( 'squirrelmail' );
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');
385 bind_textdomain_codeset ('squirrelmail', $languages[$sm_notAlias]['CHARSET'] );
389 // Use LOCALE key, if it is set.
390 if (isset($languages[$sm_notAlias]['LOCALE'])){
391 $longlocale=$languages[$sm_notAlias]['LOCALE'];
393 $longlocale=$sm_notAlias;
396 // try setting locale
397 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
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;
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" );
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');
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
431 global $text_direction, $left_align, $right_align;
432 if (isset($languages[$sm_notAlias]['DIR']) &&
433 $languages[$sm_notAlias]['DIR'] == 'rtl') {
436 * @global string $text_direction
438 $text_direction='rtl';
441 * @global string $left_align
446 * @global string $right_align
450 $text_direction='ltr';
452 $right_align='right';
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
461 // Revert to English if possible.
462 if (function_exists('setPref') && $username!='' && $data_dir!="") {
463 setPref($data_dir, $username, 'language', "en_US");
466 // stop further execution in order not to get php errors on mb_internal_encoding().
469 if (function_exists('mb_language')) {
470 mb_language('Japanese');
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 );
477 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
480 * mbstring.func_overload fix (#929644).
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
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.
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.
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');
505 * Sets default_charset variable according to the one that is used by user's translations.
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.
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.
519 function set_my_charset(){
520 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
522 $my_language = getPref($data_dir, $username, 'language');
524 $my_language = $squirrelmail_language ;
526 // Catch removed translation
527 if (!isset($languages[$my_language])) {
528 $my_language="en_US";
530 while (isset($languages[$my_language]['ALIAS'])) {
531 $my_language = $languages[$my_language]['ALIAS'];
533 $my_charset = $languages[$my_language]['CHARSET'];
534 if ($my_language!='en_US') {
535 $default_charset = $my_charset;
540 * Replaces non-braking spaces inserted by some browsers with regular space
542 * This function can be used to replace non-braking space symbols
543 * that are inserted in forms by some browsers instead of normal
546 * @param string $string Text that needs to be cleaned
547 * @param string $charset Charset used in text
548 * @return string Cleaned text
550 function cleanup_nbsp($string,$charset) {
552 // reduce number of case statements
553 if (stristr('iso-8859-',substr($charset,0,9))){
554 $output_charset="iso-8859-x";
556 if (stristr('windows-125',substr($charset,0,11))){
557 $output_charset="cp125x";
559 if (stristr('koi8',substr($charset,0,4))){
560 $output_charset="koi8-x";
562 if (! isset($output_charset)){
563 $output_charset=strtolower($charset);
566 // where is non-braking space symbol
567 switch($output_charset):
580 // don't change string if charset is unmatched
584 // return space instead of non-braking space.
585 return str_replace($nbsp,' ',$string);
589 * Function informs if it is safe to convert given charset to the one that is used by user.
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.
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
597 function is_conversion_safe($input_charset) {
598 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
600 if (isset($lossy_encoding) && $lossy_encoding )
603 // convert to lower case
604 $input_charset = strtolower($input_charset);
606 // Is user's locale Unicode based ?
607 if ( $default_charset == "utf-8" ) {
611 // Charsets that are similar
612 switch ($default_charset) {
614 if ( $input_charset == "iso-8859-5" ||
615 $input_charset == "koi8-r" ||
616 $input_charset == "koi8-u" ) {
622 if ( $input_charset == "iso-8859-13" ||
623 $input_charset == "iso-8859-4" ) {
629 if ( $input_charset == "iso-8859-13" ||
630 $input_charset == "windows-1257" ) {
636 if ( $input_charset == "windows-1251" ||
637 $input_charset == "koi8-r" ||
638 $input_charset == "koi8-u" ) {
644 if ( $input_charset == "iso-8859-4" ||
645 $input_charset == "windows-1257" ) {
651 if ( $input_charset == "windows-1251" ||
652 $input_charset == "iso-8859-5" ||
653 $input_charset == "koi8-u" ) {
659 if ( $input_charset == "windows-1251" ||
660 $input_charset == "iso-8859-5" ||
661 $input_charset == "koi8-r" ) {
672 * Converts html character entities to numeric entities
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()
679 * @param string $str string that might contain html character entities
680 * @return string string with character entities converted to decimals.
683 function sqi18n_convert_entities($str) {
687 ' ' => ' ',
688 '¡' => '¡',
689 '¢' => '¢',
690 '£' => '£',
691 '¤' => '¤',
693 '¦' => '¦',
694 '§' => '§',
696 '©' => '©',
697 'ª' => 'ª',
698 '«' => '«',
702 '¯' => '¯',
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 'É' => 'É',
729 'Ê' => 'Ê',
730 'Ë' => 'Ë',
731 'Ì' => 'Ì',
732 'Í' => 'Í',
733 'Î' => 'Î',
734 'Ï' => 'Ï',
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 'é' => 'é',
761 'ê' => 'ê',
762 'ë' => 'ë',
763 'ì' => 'ì',
764 'í' => 'í',
765 'î' => 'î',
766 'ï' => 'ï',
768 'ñ' => 'ñ',
769 'ò' => 'ò',
770 'ó' => 'ó',
771 'ô' => 'ô',
772 'õ' => 'õ',
773 'ö' => 'ö',
774 '÷' => '÷',
775 'ø' => 'ø',
776 'ù' => 'ù',
777 'ú' => 'ú',
778 'û' => 'û',
779 'ü' => 'ü',
780 'ý' => 'ý',
781 'þ' => 'þ',
782 'ÿ' => 'ÿ',
784 'Œ' => 'Œ',
785 'œ' => 'œ',
786 'Š' => 'Š',
787 'š' => 'š',
788 'Ÿ' => 'Ÿ',
789 // Spacing Modifier Letters
790 'ˆ' => 'ˆ',
791 '˜' => '˜',
792 // General Punctuation
793 ' ' => ' ',
794 ' ' => ' ',
795 ' ' => ' ',
796 '‌' => '‌',
797 '‍' => '‍',
798 '‎' => '‎',
799 '‏' => '‏',
800 '–' => '–',
801 '—' => '—',
802 '‘' => '‘',
803 '’' => '’',
804 '‚' => '‚',
805 '“' => '“',
806 '”' => '”',
807 '„' => '„',
808 '†' => '†',
809 '‡' => '‡',
810 '‰' => '‰',
811 '‹' => '‹',
812 '›' => '›',
813 '€' => '€',
815 'ƒ' => 'ƒ',
817 'Α' => 'Α',
818 'Β' => 'Β',
819 'Γ' => 'Γ',
820 'Δ' => 'Δ',
821 'Ε' => 'Ε',
822 'Ζ' => 'Ζ',
824 'Θ' => 'Θ',
825 'Ι' => 'Ι',
826 'Κ' => 'Κ',
827 'Λ' => 'Λ',
831 'Ο' => 'Ο',
834 'Σ' => 'Σ',
836 'Υ' => 'Υ',
840 'Ω' => 'Ω',
841 'α' => 'α',
842 'β' => 'β',
843 'γ' => 'γ',
844 'δ' => 'δ',
845 'ε' => 'ε',
846 'ζ' => 'ζ',
848 'θ' => 'θ',
849 'ι' => 'ι',
850 'κ' => 'κ',
851 'λ' => 'λ',
855 'ο' => 'ο',
858 'ς' => 'ς',
859 'σ' => 'σ',
861 'υ' => 'υ',
865 'ω' => 'ω',
866 'ϑ' => 'ϑ',
867 'ϒ' => 'ϒ',
869 // General Punctuation
870 '•' => '•',
871 '…' => '…',
872 '′' => '′',
873 '″' => '″',
874 '‾' => '‾',
875 '⁄' => '⁄',
876 // Letterlike Symbols
877 '℘' => '℘',
878 'ℑ' => 'ℑ',
879 'ℜ' => 'ℜ',
880 '™' => '™',
881 'ℵ' => 'ℵ',
883 '←' => '←',
884 '↑' => '↑',
885 '→' => '→',
886 '↓' => '↓',
887 '↔' => '↔',
888 '↵' => '↵',
889 '⇐' => '⇐',
890 '⇑' => '⇑',
891 '⇒' => '⇒',
892 '⇓' => '⇓',
893 '⇔' => '⇔',
894 // Mathematical Operators
895 '∀' => '∀',
896 '∂' => '∂',
897 '∃' => '∃',
898 '∅' => '∅',
899 '∇' => '∇',
900 '∈' => '∈',
901 '∉' => '∉',
903 '∏' => '∏',
904 '∑' => '∑',
905 '−' => '−',
906 '∗' => '∗',
907 '√' => '√',
908 '∝' => '∝',
909 '∞' => '∞',
910 '∠' => '∠',
911 '∧' => '∧',
913 '∩' => '∩',
914 '∪' => '∪',
915 '∫' => '∫',
916 '∴' => '∴',
917 '∼' => '∼',
918 '≅' => '≅',
919 '≈' => '≈',
921 '≡' => '≡',
924 '⊂' => '⊂',
925 '⊃' => '⊃',
926 '⊄' => '⊄',
927 '⊆' => '⊆',
928 '⊇' => '⊇',
929 '⊕' => '⊕',
930 '⊗' => '⊗',
931 '⊥' => '⊥',
932 '⋅' => '⋅',
933 // Miscellaneous Technical
934 '⌈' => '⌈',
935 '⌉' => '⌉',
936 '⌊' => '⌊',
937 '⌋' => '⌋',
938 '⟨' => '〈',
939 '⟩' => '〉',
941 '◊' => '◊',
942 // Miscellaneous Symbols
943 '♠' => '♠',
944 '♣' => '♣',
945 '♥' => '♥',
946 '♦' => '♦');
948 $str = str_replace(array_keys($entities), array_values($entities), $str);
953 /* ------------------------------ main --------------------------- */
955 global $squirrelmail_language, $languages, $use_gettext;
957 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
958 $squirrelmail_language = '';
962 * Array specifies the available translations.
964 * Structure of array:
965 * $languages['language']['variable'] = 'value'
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
976 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
979 * @global array $languages
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';
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.
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);
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');
1005 $localedir->close();
1008 /* Detect whether gettext is installed. */
1010 if (function_exists('_')) {
1011 $gettext_flags +
= 1;
1013 if (function_exists('bindtextdomain')) {
1014 $gettext_flags +
= 2;
1016 if (function_exists('textdomain')) {
1017 $gettext_flags +
= 4;
1019 if (function_exists('ngettext')) {
1020 $gettext_flags +
= 8;
1023 /* If gettext is fully loaded, cool */
1024 if ($gettext_flags == 15) {
1025 $use_gettext = true;
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');
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');
1041 /* Uh-ho. A weird install */
1042 if (! $gettext_flags & 1) {
1044 * Function is used as replacement in broken installs
1051 if (! $gettext_flags & 2) {
1053 * Function is used as replacement in broken installs
1056 function bindtextdomain() {
1060 if (! $gettext_flags & 4) {
1062 * Function is used as replacemet in broken installs
1065 function textdomain() {
1069 if (! $gettext_flags & 8) {
1071 * Function is used as replacemet in broken installs
1074 function ngettext($str,$str2,$number) {
1082 if (! function_exists('dgettext')) {
1084 * Replacement for broken setups.
1087 function dgettext($domain,$str) {
1091 if (! function_exists('dngettext')) {
1093 * Replacement for broken setups
1096 function dngettext($domain,$str1,$strn,$number) {
1097 return ($number==1 ?
$str1 : $strn);