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-2007 The SquirrelMail Project Team
18 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
20 * @package squirrelmail
26 * Wrapper for textdomain(), bindtextdomain() and
27 * bind_textdomain_codeset() primarily intended for
28 * plugins when changing into their own text domain
31 * Note that if plugins using this function have
32 * their translation files located in the SquirrelMail
33 * locale directory, the second argument is optional.
35 * @param string $domain_name The name of the text domain
36 * (usually the plugin name, or
37 * "squirrelmail") being switched to.
38 * @param string $directory The directory that contains
39 * all translations for the domain
40 * (OPTIONAL; default is SquirrelMail
45 * @since 1.5.2 and 1.4.10
47 function sq_change_text_domain($domain_name, $directory='') {
49 if (empty($directory)) $directory = SM_PATH
. 'locale/';
51 static $domains_already_seen = array();
53 // only need to call bindtextdomain() once
55 if (in_array($domain_name, $domains_already_seen)) {
56 sq_textdomain($domain_name);
60 $domains_already_seen[] = $domain_name;
62 sq_bindtextdomain($domain_name, $directory);
63 sq_textdomain($domain_name);
68 * Gettext bindtextdomain wrapper.
70 * Wrapper solves differences between php versions in order to provide
71 * ngettext support. Should be used if translation uses ngettext
74 * This also provides a bind_textdomain_codeset call to make sure the
75 * domain's encoding will not be overridden.
77 * @since 1.4.10 and 1.5.1
78 * @param string $domain gettext domain name
79 * @param string $dir directory that contains all translations (OPTIONAL;
80 * if not specified, defaults to SquirrelMail locale
82 * @return string path to translation directory
84 function sq_bindtextdomain($domain,$dir='') {
85 global $l10n, $gettext_flags, $sm_notAlias;
87 if (empty($dir)) $dir = SM_PATH
. 'locale/'
89 if ($gettext_flags==7) {
90 // gettext extension without ngettext
91 if (substr($dir, -1) != '/') $dir .= '/';
92 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
93 $input = new FileReader($mofile);
94 $l10n[$domain] = new gettext_reader($input);
97 $dir=bindtextdomain($domain,$dir);
99 // set codeset in order to avoid gettext charset conversions
100 if (function_exists('bind_textdomain_codeset')
101 && isset($languages[$sm_notAlias]['CHARSET'])) {
103 // Japanese translation uses different internal charset
104 if ($sm_notAlias == 'ja_JP') {
105 bind_textdomain_codeset ($domain_name, 'EUC-JP');
107 bind_textdomain_codeset ($domain_name, $languages[$sm_notAlias]['CHARSET']);
116 * Gettext textdomain wrapper.
117 * Makes sure that gettext_domain global is modified.
119 * @param string $name gettext domain name
120 * @return string gettext domain name
122 function sq_textdomain($domain) {
123 global $gettext_domain;
124 $gettext_domain=textdomain($domain);
125 return $gettext_domain;
129 * php setlocale function wrapper
131 * From php 4.3.0 it is possible to use arrays in order to set locale.
132 * php gettext extension works only when locale is set. This wrapper
133 * function allows to use more than one locale name.
135 * @param int $category locale category name. Use php named constants
136 * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME)
137 * @param mixed $locale option contains array with possible locales or string with one locale
138 * @return string name of set locale or false, if all locales fail.
139 * @since 1.5.1 and 1.4.5
140 * @see http://www.php.net/setlocale
142 function sq_setlocale($category,$locale) {
143 if (is_string($locale)) {
144 // string with only one locale
145 $ret = setlocale($category,$locale);
146 } elseif (! check_php_version(4,3)) {
147 // older php version (second setlocale argument must be string)
150 while ( ! $ret && $index<count($locale)) {
151 $ret=setlocale($category,$locale[$index]);
155 // php 4.3.0 or better, use entire array
156 $ret=setlocale($category,$locale);
160 if (preg_match("/^.*\/.*\/.*\/.*\/.*\/.*$/",$ret)) {
162 * Welcome to We-Don't-Follow-Own-Fine-Manual department
163 * OpenBSD 3.8, 3.9-current and maybe later versions
164 * return invalid response to setlocale command.
165 * SM bug report #1427512.
173 * Converts string from given charset to charset, that can be displayed by user translation.
175 * Function by default returns html encoded strings, if translation uses different encoding.
176 * If Japanese translation is used - function returns string converted to euc-jp
177 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
178 * If $charset is not supported - function returns unconverted string.
180 * sanitizing of html tags is also done by this function.
182 * @param string $charset
183 * @param string $string Text to be decoded
184 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
185 * Argument is available since 1.5.1 and 1.4.5.
186 * @param boolean $save_html disables htmlspecialchars() in order to preserve
187 * html formating. Use with care. Available since 1.5.1
188 * @return string decoded string
190 function charset_decode ($charset, $string, $force_decode=false, $save_html=false) {
191 global $languages, $squirrelmail_language, $default_charset;
192 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
194 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
195 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
196 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
199 $charset = strtolower($charset);
203 // Variables that allow to use functions without function_exist() calls
204 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
205 $use_php_recode=false; }
206 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
207 $use_php_iconv=false; }
209 // Don't do conversion if charset is the same.
210 if ( ! $force_decode && $charset == strtolower($default_charset) )
211 return ($save_html ?
$string : htmlspecialchars($string));
213 // catch iso-8859-8-i thing
214 if ( $charset == "iso-8859-8-i" )
215 $charset = "iso-8859-8";
218 * Recode converts html special characters automatically if you use
219 * 'charset..html' decoding. There is no documented way to put -d option
220 * into php recode function call.
222 if ( $use_php_recode ) {
223 if ( $default_charset == "utf-8" ) {
224 // other charsets can be converted to utf-8 without loss.
225 // and output string is smaller
226 $string = recode_string($charset . "..utf-8",$string);
227 return ($save_html ?
$string : htmlspecialchars($string));
229 $string = recode_string($charset . "..html",$string);
230 // recode does not convert single quote, htmlspecialchars does.
231 $string = str_replace("'", ''', $string);
232 // undo html specialchars
234 $string=str_replace(array('&','"','<','>'),
235 array('&','"','<','>'),$string);
240 // iconv functions does not have html target and can be used only with utf-8
241 if ( $use_php_iconv && $default_charset=='utf-8') {
242 $string = iconv($charset,$default_charset,$string);
243 return ($save_html ?
$string : htmlspecialchars($string));
246 // If we don't use recode and iconv, we'll do it old way.
248 /* All HTML special characters are 7 bit and can be replaced first */
249 if (! $save_html) $string = htmlspecialchars ($string);
251 /* controls cpu and memory intensive decoding cycles */
252 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
253 $aggressive_decoding=false; }
255 $decode=fixcharset($charset);
256 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
257 if ($decode != 'index' && file_exists($decodefile)) {
258 include_once($decodefile);
259 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
260 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
268 * Converts html string to given charset
269 * @since 1.5.1 and 1.4.4
270 * @param string $string
271 * @param string $charset
272 * @param boolean $htmlencode keep htmlspecialchars encoding
275 function charset_encode($string,$charset,$htmlencode=true) {
276 global $default_charset;
278 $encode=fixcharset($charset);
279 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
280 if ($encode != 'index' && file_exists($encodefile)) {
281 include_once($encodefile);
282 $ret = call_user_func('charset_encode_'.$encode, $string);
283 } elseif(file_exists(SM_PATH
. 'functions/encode/us_ascii.php')) {
284 // function replaces all 8bit html entities with question marks.
285 // it is used when other encoding functions are unavailable
286 include_once(SM_PATH
. 'functions/encode/us_ascii.php');
287 $ret = charset_encode_us_ascii($string);
290 * fix for yahoo users that remove all us-ascii related things
296 * Undo html special chars, some places (like compose form) have
297 * own sanitizing functions and don't need html symbols.
298 * Undo chars only after encoding in order to prevent conversion of
299 * html entities in plain text emails.
301 if (! $htmlencode ) {
302 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
308 * Combined decoding and encoding functions
310 * If conversion is done to charset different that utf-8, unsupported symbols
311 * will be replaced with question marks.
312 * @since 1.5.1 and 1.4.4
313 * @param string $in_charset initial charset
314 * @param string $string string that has to be converted
315 * @param string $out_charset final charset
316 * @param boolean $htmlencode keep htmlspecialchars encoding
317 * @return string converted string
319 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
320 $string=charset_decode($in_charset,$string,true);
321 $string=sqi18n_convert_entities($string);
322 $string=charset_encode($string,$out_charset,$htmlencode);
327 * Makes charset name suitable for decoding cycles
329 * @since 1.5.0 and 1.4.4
330 * @param string $charset Name of charset
331 * @return string $charset Adjusted name of charset
333 function fixcharset($charset) {
334 /* remove minus and characters that might be used in paths from charset
335 * name in order to be able to use it in function names and include calls.
337 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
339 // OE ks_c_5601_1987 > cp949
340 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
341 // Moz x-euc-tw > euc-tw
342 $charset=str_replace('x_euc','euc',$charset);
343 // Moz x-windows-949 > cp949
344 $charset=str_replace('x_windows_','cp',$charset);
346 // windows-125x and cp125x charsets
347 $charset=str_replace('windows_','cp',$charset);
350 $charset=str_replace('ibm','cp',$charset);
352 // iso-8859-8-i -> iso-8859-8
353 // use same cycle until I'll find differences
354 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
360 * Set up the language to be output
361 * if $do_search is true, then scan the browser information
362 * for a possible language that we know
364 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
365 * gettext translation bindings and html header information.
367 * Function returns error codes, if there is some fatal error.
369 * 1 = mbstring support is not present,
370 * 2 = mbstring support is not present, user's translation reverted to en_US.
372 * @param string $sm_language translation used by user's interface
373 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
374 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
375 * @return int function execution error codes.
377 function set_up_language($sm_language, $do_search = false, $default = false) {
379 static $SetupAlready = 0;
380 global $use_gettext, $languages,
381 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
382 $sm_notAlias, $username, $data_dir;
388 $SetupAlready = TRUE;
389 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
392 * If function is asked to detect preferred language
393 * OR squirrelmail default language is set to empty string
395 * squirrelmail language ($sm_language) is empty string
396 * (not set in user's prefs and no cookie with language info)
398 * browser provides list of preferred languages
400 * get preferred language from HTTP_ACCEPT_LANGUAGE header
402 if (($do_search ||
empty($squirrelmail_default_language)) &&
404 isset($accept_lang)) {
405 // TODO: use more than one language, if first language is not available
406 // FIXME: function assumes that string contains two or more characters.
407 // FIXME: some languages use 5 chars
408 $sm_language = substr($accept_lang, 0, 2);
412 * If language preference is not set OR script asks to use default language
414 * default squirrelmail language is not set to empty string
416 * use default squirrelmail language value from configuration.
418 if ((!$sm_language||
$default) &&
419 ! empty($squirrelmail_default_language)) {
420 $squirrelmail_language = $squirrelmail_default_language;
421 $sm_language = $squirrelmail_default_language;
424 /** provide failsafe language when detection fails */
425 if (! $sm_language) $sm_language='en_US';
427 $sm_notAlias = $sm_language;
429 // Catching removed translation
430 // System reverts to English translation if user prefs contain translation
431 // that is not available in $languages array
432 if (!isset($languages[$sm_notAlias])) {
433 $sm_notAlias="en_US";
436 while (isset($languages[$sm_notAlias]['ALIAS'])) {
437 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
440 if ( isset($sm_language) &&
442 $sm_language != '' &&
443 isset($languages[$sm_notAlias]['CHARSET']) ) {
444 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
445 sq_textdomain( 'squirrelmail' );
447 // Use LOCALE key, if it is set.
448 if (isset($languages[$sm_notAlias]['LOCALE'])){
449 $longlocale=$languages[$sm_notAlias]['LOCALE'];
451 $longlocale=$sm_notAlias;
454 // try setting locale
455 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
457 // check if locale is set and assign that locale to $longlocale
458 // in order to use it in putenv calls.
459 if (! is_bool($retlocale)) {
460 $longlocale=$retlocale;
461 } elseif (is_array($longlocale)) {
462 // setting of all locales failed.
463 // we need string instead of array used in LOCALE key.
464 $longlocale=$sm_notAlias;
467 if ( !((bool)ini_get('safe_mode')) &&
468 getenv( 'LC_ALL' ) != $longlocale ) {
469 putenv( "LC_ALL=$longlocale" );
470 putenv( "LANG=$longlocale" );
471 putenv( "LANGUAGE=$longlocale" );
472 putenv( "LC_NUMERIC=C" );
473 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
475 // Workaround for plugins that use numbers with floating point
476 // It might be removed if plugins use correct decimal delimiters
477 // according to locale settings.
478 setlocale(LC_NUMERIC
, 'C');
479 // Workaround for specific Turkish strtolower/strtoupper rules.
480 // Many functions expect English conversion rules.
481 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
484 * Set text direction/alignment variables
485 * When language environment is setup, scripts can use these globals
486 * without accessing $languages directly and making checks for optional
489 global $text_direction, $left_align, $right_align;
490 if (isset($languages[$sm_notAlias]['DIR']) &&
491 $languages[$sm_notAlias]['DIR'] == 'rtl') {
494 * @global string $text_direction
496 $text_direction='rtl';
499 * @global string $left_align
504 * @global string $right_align
508 $text_direction='ltr';
510 $right_align='right';
513 $squirrelmail_language = $sm_notAlias;
514 if ($squirrelmail_language == 'ja_JP') {
515 header ('Content-Type: text/html; charset=EUC-JP');
516 if (!function_exists('mb_internal_encoding')) {
517 // Error messages can't be displayed here
519 // Revert to English if possible.
520 if (function_exists('setPref') && $username!='' && $data_dir!="") {
521 setPref($data_dir, $username, 'language', "en_US");
524 // stop further execution in order not to get php errors on mb_internal_encoding().
527 if (function_exists('mb_language')) {
528 mb_language('Japanese');
530 mb_internal_encoding('EUC-JP');
531 mb_http_output('pass');
532 } elseif ($squirrelmail_language == 'en_US') {
533 header( 'Content-Type: text/html; charset=' . $default_charset );
535 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
538 * mbstring.func_overload fix (#929644).
540 * php mbstring extension can replace standard string functions with their multibyte
541 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
542 * was added in php v.4.2.0
544 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
545 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
546 * interface can't trust regular string functions. Due to mbstring overloading design
547 * limits php scripts can't control this setting.
549 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
550 * to disable mbstring overloading. Japanese translation uses different internal encoding.
552 if ($squirrelmail_language != 'ja_JP' &&
553 function_exists('mb_internal_encoding') &&
554 check_php_version(4,2,0) &&
555 (int)ini_get('mbstring.func_overload')!=0) {
556 mb_internal_encoding('pass');
563 * Sets default_charset variable according to the one that is used by user's translations.
565 * Function changes global $default_charset variable in order to be sure, that it
566 * contains charset used by user's translation. Sanity of $squirrelmail_language
567 * and $default_charset combination is also tested.
569 * There can be a $default_charset setting in the
570 * config.php file, but the user may have a different language
571 * selected for a user interface. This function checks the
572 * language selected by the user and tags the outgoing messages
573 * with the appropriate charset corresponding to the language
574 * selection. This is "more right" (tm), than just stamping the
575 * message blindly with the system-wide $default_charset.
577 function set_my_charset(){
578 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
580 $my_language = getPref($data_dir, $username, 'language');
582 $my_language = $squirrelmail_language ;
584 // Catch removed translation
585 if (!isset($languages[$my_language])) {
586 $my_language="en_US";
588 while (isset($languages[$my_language]['ALIAS'])) {
589 $my_language = $languages[$my_language]['ALIAS'];
591 $my_charset = $languages[$my_language]['CHARSET'];
592 if ($my_language!='en_US') {
593 $default_charset = $my_charset;
598 * Replaces non-braking spaces inserted by some browsers with regular space
600 * This function can be used to replace non-braking space symbols
601 * that are inserted in forms by some browsers instead of normal
604 * @param string $string Text that needs to be cleaned
605 * @param string $charset Charset used in text
606 * @return string Cleaned text
608 function cleanup_nbsp($string,$charset) {
610 // reduce number of case statements
611 if (stristr('iso-8859-',substr($charset,0,9))){
612 $output_charset="iso-8859-x";
614 if (stristr('windows-125',substr($charset,0,11))){
615 $output_charset="cp125x";
617 if (stristr('koi8',substr($charset,0,4))){
618 $output_charset="koi8-x";
620 if (! isset($output_charset)){
621 $output_charset=strtolower($charset);
624 // where is non-braking space symbol
625 switch($output_charset):
638 // don't change string if charset is unmatched
642 // return space instead of non-braking space.
643 return str_replace($nbsp,' ',$string);
647 * Function informs if it is safe to convert given charset to the one that is used by user.
649 * It is safe to use conversion only if user uses utf-8 encoding and when
650 * converted charset is similar to the one that is used by user.
652 * @param string $input_charset Charset of text that needs to be converted
653 * @return bool is it possible to convert to user's charset
655 function is_conversion_safe($input_charset) {
656 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
658 if (isset($lossy_encoding) && $lossy_encoding )
661 // convert to lower case
662 $input_charset = strtolower($input_charset);
664 // Is user's locale Unicode based ?
665 if ( $default_charset == "utf-8" ) {
669 // Charsets that are similar
670 switch ($default_charset) {
672 if ( $input_charset == "iso-8859-5" ||
673 $input_charset == "koi8-r" ||
674 $input_charset == "koi8-u" ) {
680 if ( $input_charset == "iso-8859-13" ||
681 $input_charset == "iso-8859-4" ) {
687 if ( $input_charset == "iso-8859-13" ||
688 $input_charset == "windows-1257" ) {
694 if ( $input_charset == "windows-1251" ||
695 $input_charset == "koi8-r" ||
696 $input_charset == "koi8-u" ) {
702 if ( $input_charset == "iso-8859-4" ||
703 $input_charset == "windows-1257" ) {
709 if ( $input_charset == "windows-1251" ||
710 $input_charset == "iso-8859-5" ||
711 $input_charset == "koi8-u" ) {
717 if ( $input_charset == "windows-1251" ||
718 $input_charset == "iso-8859-5" ||
719 $input_charset == "koi8-r" ) {
730 * Converts html character entities to numeric entities
732 * SquirrelMail encoding functions work only with numeric entities.
733 * This function fixes issues with decoding functions that might convert
734 * some symbols to character entities. Issue is specific to PHP recode
735 * extension decoding. Function is used internally in charset_convert()
737 * @param string $str string that might contain html character entities
738 * @return string string with character entities converted to decimals.
741 function sqi18n_convert_entities($str) {
745 ' ' => ' ',
746 '¡' => '¡',
747 '¢' => '¢',
748 '£' => '£',
749 '¤' => '¤',
751 '¦' => '¦',
752 '§' => '§',
754 '©' => '©',
755 'ª' => 'ª',
756 '«' => '«',
760 '¯' => '¯',
762 '±' => '±',
763 '²' => '²',
764 '³' => '³',
765 '´' => '´',
766 'µ' => 'µ',
767 '¶' => '¶',
768 '·' => '·',
769 '¸' => '¸',
770 '¹' => '¹',
771 'º' => 'º',
772 '»' => '»',
773 '¼' => '¼',
774 '½' => '½',
775 '¾' => '¾',
776 '¿' => '¿',
777 'À' => 'À',
778 'Á' => 'Á',
779 'Â' => 'Â',
780 'Ã' => 'Ã',
781 'Ä' => 'Ä',
782 'Å' => 'Å',
783 'Æ' => 'Æ',
784 'Ç' => 'Ç',
785 'È' => 'È',
786 'É' => 'É',
787 'Ê' => 'Ê',
788 'Ë' => 'Ë',
789 'Ì' => 'Ì',
790 'Í' => 'Í',
791 'Î' => 'Î',
792 'Ï' => 'Ï',
794 'Ñ' => 'Ñ',
795 'Ò' => 'Ò',
796 'Ó' => 'Ó',
797 'Ô' => 'Ô',
798 'Õ' => 'Õ',
799 'Ö' => 'Ö',
800 '×' => '×',
801 'Ø' => 'Ø',
802 'Ù' => 'Ù',
803 'Ú' => 'Ú',
804 'Û' => 'Û',
805 'Ü' => 'Ü',
806 'Ý' => 'Ý',
807 'Þ' => 'Þ',
808 'ß' => 'ß',
809 'à' => 'à',
810 'á' => 'á',
811 'â' => 'â',
812 'ã' => 'ã',
813 'ä' => 'ä',
814 'å' => 'å',
815 'æ' => 'æ',
816 'ç' => 'ç',
817 'è' => 'è',
818 'é' => 'é',
819 'ê' => 'ê',
820 'ë' => 'ë',
821 'ì' => 'ì',
822 'í' => 'í',
823 'î' => 'î',
824 'ï' => 'ï',
826 'ñ' => 'ñ',
827 'ò' => 'ò',
828 'ó' => 'ó',
829 'ô' => 'ô',
830 'õ' => 'õ',
831 'ö' => 'ö',
832 '÷' => '÷',
833 'ø' => 'ø',
834 'ù' => 'ù',
835 'ú' => 'ú',
836 'û' => 'û',
837 'ü' => 'ü',
838 'ý' => 'ý',
839 'þ' => 'þ',
840 'ÿ' => 'ÿ',
842 'Œ' => 'Œ',
843 'œ' => 'œ',
844 'Š' => 'Š',
845 'š' => 'š',
846 'Ÿ' => 'Ÿ',
847 // Spacing Modifier Letters
848 'ˆ' => 'ˆ',
849 '˜' => '˜',
850 // General Punctuation
851 ' ' => ' ',
852 ' ' => ' ',
853 ' ' => ' ',
854 '‌' => '‌',
855 '‍' => '‍',
856 '‎' => '‎',
857 '‏' => '‏',
858 '–' => '–',
859 '—' => '—',
860 '‘' => '‘',
861 '’' => '’',
862 '‚' => '‚',
863 '“' => '“',
864 '”' => '”',
865 '„' => '„',
866 '†' => '†',
867 '‡' => '‡',
868 '‰' => '‰',
869 '‹' => '‹',
870 '›' => '›',
871 '€' => '€',
873 'ƒ' => 'ƒ',
875 'Α' => 'Α',
876 'Β' => 'Β',
877 'Γ' => 'Γ',
878 'Δ' => 'Δ',
879 'Ε' => 'Ε',
880 'Ζ' => 'Ζ',
882 'Θ' => 'Θ',
883 'Ι' => 'Ι',
884 'Κ' => 'Κ',
885 'Λ' => 'Λ',
889 'Ο' => 'Ο',
892 'Σ' => 'Σ',
894 'Υ' => 'Υ',
898 'Ω' => 'Ω',
899 'α' => 'α',
900 'β' => 'β',
901 'γ' => 'γ',
902 'δ' => 'δ',
903 'ε' => 'ε',
904 'ζ' => 'ζ',
906 'θ' => 'θ',
907 'ι' => 'ι',
908 'κ' => 'κ',
909 'λ' => 'λ',
913 'ο' => 'ο',
916 'ς' => 'ς',
917 'σ' => 'σ',
919 'υ' => 'υ',
923 'ω' => 'ω',
924 'ϑ' => 'ϑ',
925 'ϒ' => 'ϒ',
927 // General Punctuation
928 '•' => '•',
929 '…' => '…',
930 '′' => '′',
931 '″' => '″',
932 '‾' => '‾',
933 '⁄' => '⁄',
934 // Letterlike Symbols
935 '℘' => '℘',
936 'ℑ' => 'ℑ',
937 'ℜ' => 'ℜ',
938 '™' => '™',
939 'ℵ' => 'ℵ',
941 '←' => '←',
942 '↑' => '↑',
943 '→' => '→',
944 '↓' => '↓',
945 '↔' => '↔',
946 '↵' => '↵',
947 '⇐' => '⇐',
948 '⇑' => '⇑',
949 '⇒' => '⇒',
950 '⇓' => '⇓',
951 '⇔' => '⇔',
952 // Mathematical Operators
953 '∀' => '∀',
954 '∂' => '∂',
955 '∃' => '∃',
956 '∅' => '∅',
957 '∇' => '∇',
958 '∈' => '∈',
959 '∉' => '∉',
961 '∏' => '∏',
962 '∑' => '∑',
963 '−' => '−',
964 '∗' => '∗',
965 '√' => '√',
966 '∝' => '∝',
967 '∞' => '∞',
968 '∠' => '∠',
969 '∧' => '∧',
971 '∩' => '∩',
972 '∪' => '∪',
973 '∫' => '∫',
974 '∴' => '∴',
975 '∼' => '∼',
976 '≅' => '≅',
977 '≈' => '≈',
979 '≡' => '≡',
982 '⊂' => '⊂',
983 '⊃' => '⊃',
984 '⊄' => '⊄',
985 '⊆' => '⊆',
986 '⊇' => '⊇',
987 '⊕' => '⊕',
988 '⊗' => '⊗',
989 '⊥' => '⊥',
990 '⋅' => '⋅',
991 // Miscellaneous Technical
992 '⌈' => '⌈',
993 '⌉' => '⌉',
994 '⌊' => '⌊',
995 '⌋' => '⌋',
996 '⟨' => '〈',
997 '⟩' => '〉',
999 '◊' => '◊',
1000 // Miscellaneous Symbols
1001 '♠' => '♠',
1002 '♣' => '♣',
1003 '♥' => '♥',
1004 '♦' => '♦');
1006 $str = str_replace(array_keys($entities), array_values($entities), $str);
1011 /* ------------------------------ main --------------------------- */
1013 global $squirrelmail_language, $languages, $use_gettext;
1015 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
1016 $squirrelmail_language = '';
1020 * Array specifies the available translations.
1022 * Structure of array:
1023 * $languages['language']['variable'] = 'value'
1025 * Possible 'variable' names:
1026 * NAME - Translation name in English
1027 * CHARSET - Encoding used by translation
1028 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
1029 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
1030 * 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
1031 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
1032 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
1034 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
1037 * @global array $languages
1039 $languages['en_US']['NAME'] = 'English';
1040 $languages['en_US']['CHARSET'] = 'iso-8859-1';
1041 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
1042 $languages['en']['ALIAS'] = 'en_US';
1045 * Automatic translation loading from setup.php files.
1046 * Solution for bug. 1240889.
1047 * setup.php file can contain $languages array entries and XTRA_CODE functions.
1049 if (is_dir(SM_PATH
. 'locale') &&
1050 is_readable(SM_PATH
. 'locale')) {
1051 $localedir = dir(SM_PATH
. 'locale');
1052 while($lang_dir=$localedir->read()) {
1053 // remove trailing slash, if present
1054 if (substr($lang_dir,-1)=='/') {
1055 $lang_dir = substr($lang_dir,0,-1);
1057 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
1058 $lang_dir != '.svn' && is_dir(SM_PATH
.'locale/'.$lang_dir) &&
1059 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
1060 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1063 $localedir->close();
1066 /* Detect whether gettext is installed. */
1068 if (function_exists('_')) {
1069 $gettext_flags +
= 1;
1071 if (function_exists('bindtextdomain')) {
1072 $gettext_flags +
= 2;
1074 if (function_exists('textdomain')) {
1075 $gettext_flags +
= 4;
1077 if (function_exists('ngettext')) {
1078 $gettext_flags +
= 8;
1081 /* If gettext is fully loaded, cool */
1082 if ($gettext_flags == 15) {
1083 $use_gettext = true;
1086 /* If ngettext support is missing, load it */
1087 elseif ($gettext_flags == 7) {
1088 $use_gettext = true;
1089 // load internal ngettext functions
1090 include_once(SM_PATH
. 'class/l10n.class.php');
1091 include_once(SM_PATH
. 'functions/ngettext.php');
1094 /* If we can fake gettext, try that */
1095 elseif ($gettext_flags == 0) {
1096 $use_gettext = true;
1097 include_once(SM_PATH
. 'functions/gettext.php');
1099 /* Uh-ho. A weird install */
1100 if (! $gettext_flags & 1) {
1102 * Function is used as replacement in broken installs
1109 if (! $gettext_flags & 2) {
1111 * Function is used as replacement in broken installs
1114 function bindtextdomain() {
1118 if (! $gettext_flags & 4) {
1120 * Function is used as replacemet in broken installs
1123 function textdomain() {
1127 if (! $gettext_flags & 8) {
1129 * Function is used as replacemet in broken installs
1132 function ngettext($str,$str2,$number) {
1140 if (! function_exists('dgettext')) {
1142 * Replacement for broken setups.
1145 function dgettext($domain,$str) {
1149 if (! function_exists('dngettext')) {
1151 * Replacement for broken setups
1154 function dngettext($domain,$str1,$strn,$number) {
1155 return ($number==1 ?
$str1 : $strn);