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
43 * @return string The name of the text domain that was set
44 * *BEFORE* it is changed herein - NOTE that
45 * this differs from PHP's textdomain()
47 * @since 1.5.2 and 1.4.10
49 function sq_change_text_domain($domain_name, $directory='') {
51 static $domains_already_seen = array();
52 global $gettext_domain;
53 $return_value = $gettext_domain;
55 // only need to call bindtextdomain() once
57 if (in_array($domain_name, $domains_already_seen)) {
58 sq_textdomain($domain_name);
62 $domains_already_seen[] = $domain_name;
64 if (empty($directory)) $directory = SM_PATH
. 'locale/';
66 sq_bindtextdomain($domain_name, $directory);
67 sq_textdomain($domain_name);
73 * Gettext bindtextdomain wrapper.
75 * Wrapper solves differences between php versions in order to provide
76 * ngettext support. Should be used if translation uses ngettext
79 * This also provides a bind_textdomain_codeset call to make sure the
80 * domain's encoding will not be overridden.
82 * @since 1.4.10 and 1.5.1
83 * @param string $domain gettext domain name
84 * @param string $dir directory that contains all translations (OPTIONAL;
85 * if not specified, defaults to SquirrelMail locale
87 * @return string path to translation directory
89 function sq_bindtextdomain($domain,$dir='') {
90 global $l10n, $gettext_flags, $sm_notAlias;
92 if (empty($dir)) $dir = SM_PATH
. 'locale/';
94 if ($gettext_flags==7) {
95 // gettext extension without ngettext
96 if (substr($dir, -1) != '/') $dir .= '/';
97 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
98 $input = new FileReader($mofile);
99 $l10n[$domain] = new gettext_reader($input);
102 $dir=bindtextdomain($domain,$dir);
104 // set codeset in order to avoid gettext charset conversions
105 if (function_exists('bind_textdomain_codeset')
106 && isset($languages[$sm_notAlias]['CHARSET'])) {
108 // Japanese translation uses different internal charset
109 if ($sm_notAlias == 'ja_JP') {
110 bind_textdomain_codeset ($domain_name, 'EUC-JP');
112 bind_textdomain_codeset ($domain_name, $languages[$sm_notAlias]['CHARSET']);
121 * Gettext textdomain wrapper.
122 * Makes sure that gettext_domain global is modified.
124 * @param string $name gettext domain name
125 * @return string gettext domain name
127 function sq_textdomain($domain) {
128 global $gettext_domain;
129 $gettext_domain=textdomain($domain);
130 return $gettext_domain;
134 * php setlocale function wrapper
136 * From php 4.3.0 it is possible to use arrays in order to set locale.
137 * php gettext extension works only when locale is set. This wrapper
138 * function allows to use more than one locale name.
140 * @param int $category locale category name. Use php named constants
141 * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME)
142 * @param mixed $locale option contains array with possible locales or string with one locale
143 * @return string name of set locale or false, if all locales fail.
144 * @since 1.5.1 and 1.4.5
145 * @see http://www.php.net/setlocale
147 function sq_setlocale($category,$locale) {
148 if (is_string($locale)) {
149 // string with only one locale
150 $ret = setlocale($category,$locale);
151 } elseif (! check_php_version(4,3)) {
152 // older php version (second setlocale argument must be string)
155 while ( ! $ret && $index<count($locale)) {
156 $ret=setlocale($category,$locale[$index]);
160 // php 4.3.0 or better, use entire array
161 $ret=setlocale($category,$locale);
165 if (preg_match("/^.*\/.*\/.*\/.*\/.*\/.*$/",$ret)) {
167 * Welcome to We-Don't-Follow-Own-Fine-Manual department
168 * OpenBSD 3.8, 3.9-current and maybe later versions
169 * return invalid response to setlocale command.
170 * SM bug report #1427512.
178 * Converts string from given charset to charset, that can be displayed by user translation.
180 * Function by default returns html encoded strings, if translation uses different encoding.
181 * If Japanese translation is used - function returns string converted to euc-jp
182 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
183 * If $charset is not supported - function returns unconverted string.
185 * sanitizing of html tags is also done by this function.
187 * @param string $charset
188 * @param string $string Text to be decoded
189 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
190 * Argument is available since 1.5.1 and 1.4.5.
191 * @param boolean $save_html disables htmlspecialchars() in order to preserve
192 * html formating. Use with care. Available since 1.5.1
193 * @return string decoded string
195 function charset_decode ($charset, $string, $force_decode=false, $save_html=false) {
196 global $languages, $squirrelmail_language, $default_charset;
197 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
199 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
200 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
201 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
204 $charset = strtolower($charset);
208 // Variables that allow to use functions without function_exist() calls
209 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
210 $use_php_recode=false; }
211 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
212 $use_php_iconv=false; }
214 // Don't do conversion if charset is the same.
215 if ( ! $force_decode && $charset == strtolower($default_charset) )
216 return ($save_html ?
$string : htmlspecialchars($string));
218 // catch iso-8859-8-i thing
219 if ( $charset == "iso-8859-8-i" )
220 $charset = "iso-8859-8";
223 * Recode converts html special characters automatically if you use
224 * 'charset..html' decoding. There is no documented way to put -d option
225 * into php recode function call.
227 if ( $use_php_recode ) {
228 if ( $default_charset == "utf-8" ) {
229 // other charsets can be converted to utf-8 without loss.
230 // and output string is smaller
231 $string = recode_string($charset . "..utf-8",$string);
232 return ($save_html ?
$string : htmlspecialchars($string));
234 $string = recode_string($charset . "..html",$string);
235 // recode does not convert single quote, htmlspecialchars does.
236 $string = str_replace("'", ''', $string);
237 // undo html specialchars
239 $string=str_replace(array('&','"','<','>'),
240 array('&','"','<','>'),$string);
245 // iconv functions does not have html target and can be used only with utf-8
246 if ( $use_php_iconv && $default_charset=='utf-8') {
247 $string = iconv($charset,$default_charset,$string);
248 return ($save_html ?
$string : htmlspecialchars($string));
251 // If we don't use recode and iconv, we'll do it old way.
253 /* All HTML special characters are 7 bit and can be replaced first */
254 if (! $save_html) $string = htmlspecialchars ($string);
256 /* controls cpu and memory intensive decoding cycles */
257 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
258 $aggressive_decoding=false; }
260 $decode=fixcharset($charset);
261 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
262 if ($decode != 'index' && file_exists($decodefile)) {
263 include_once($decodefile);
264 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
265 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
273 * Converts html string to given charset
274 * @since 1.5.1 and 1.4.4
275 * @param string $string
276 * @param string $charset
277 * @param boolean $htmlencode keep htmlspecialchars encoding
280 function charset_encode($string,$charset,$htmlencode=true) {
281 global $default_charset;
283 $encode=fixcharset($charset);
284 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
285 if ($encode != 'index' && file_exists($encodefile)) {
286 include_once($encodefile);
287 $ret = call_user_func('charset_encode_'.$encode, $string);
288 } elseif(file_exists(SM_PATH
. 'functions/encode/us_ascii.php')) {
289 // function replaces all 8bit html entities with question marks.
290 // it is used when other encoding functions are unavailable
291 include_once(SM_PATH
. 'functions/encode/us_ascii.php');
292 $ret = charset_encode_us_ascii($string);
295 * fix for yahoo users that remove all us-ascii related things
301 * Undo html special chars, some places (like compose form) have
302 * own sanitizing functions and don't need html symbols.
303 * Undo chars only after encoding in order to prevent conversion of
304 * html entities in plain text emails.
306 if (! $htmlencode ) {
307 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
313 * Combined decoding and encoding functions
315 * If conversion is done to charset different that utf-8, unsupported symbols
316 * will be replaced with question marks.
317 * @since 1.5.1 and 1.4.4
318 * @param string $in_charset initial charset
319 * @param string $string string that has to be converted
320 * @param string $out_charset final charset
321 * @param boolean $htmlencode keep htmlspecialchars encoding
322 * @return string converted string
324 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
325 $string=charset_decode($in_charset,$string,true);
326 $string=sqi18n_convert_entities($string);
327 $string=charset_encode($string,$out_charset,$htmlencode);
332 * Makes charset name suitable for decoding cycles
334 * @since 1.5.0 and 1.4.4
335 * @param string $charset Name of charset
336 * @return string $charset Adjusted name of charset
338 function fixcharset($charset) {
339 /* remove minus and characters that might be used in paths from charset
340 * name in order to be able to use it in function names and include calls.
342 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
344 // OE ks_c_5601_1987 > cp949
345 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
346 // Moz x-euc-tw > euc-tw
347 $charset=str_replace('x_euc','euc',$charset);
348 // Moz x-windows-949 > cp949
349 $charset=str_replace('x_windows_','cp',$charset);
351 // windows-125x and cp125x charsets
352 $charset=str_replace('windows_','cp',$charset);
355 $charset=str_replace('ibm','cp',$charset);
357 // iso-8859-8-i -> iso-8859-8
358 // use same cycle until I'll find differences
359 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
365 * Set up the language to be output
366 * if $do_search is true, then scan the browser information
367 * for a possible language that we know
369 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
370 * gettext translation bindings and html header information.
372 * Function returns error codes, if there is some fatal error.
374 * 1 = mbstring support is not present,
375 * 2 = mbstring support is not present, user's translation reverted to en_US.
377 * @param string $sm_language Translation used by user's interface
378 * @param bool $do_search Use browser's preferred language detection functions.
380 * @param bool $default Set $sm_language to $squirrelmail_default_language if
381 * language detection fails or language is not set.
383 * @param string $content_type The content type being served currently (OPTIONAL;
384 * if not specified, defaults to whatever the template
385 * set that is in use has defined).
387 * @return int function execution error codes.
390 function set_up_language($sm_language, $do_search=false,
391 $default=false, $content_type='') {
393 static $SetupAlready = 0;
394 global $use_gettext, $languages, $oTemplate,
395 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
396 $sm_notAlias, $username, $data_dir;
402 $SetupAlready = TRUE;
403 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
405 // grab content type if needed
407 if (empty($content_type)) $content_type = $oTemplate->get_content_type();
410 * If function is asked to detect preferred language
411 * OR squirrelmail default language is set to empty string
413 * squirrelmail language ($sm_language) is empty string
414 * (not set in user's prefs and no cookie with language info)
416 * browser provides list of preferred languages
418 * get preferred language from HTTP_ACCEPT_LANGUAGE header
420 if (($do_search ||
empty($squirrelmail_default_language)) &&
422 isset($accept_lang)) {
423 // TODO: use more than one language, if first language is not available
424 // FIXME: function assumes that string contains two or more characters.
425 // FIXME: some languages use 5 chars
426 $sm_language = substr($accept_lang, 0, 2);
430 * If language preference is not set OR script asks to use default language
432 * default squirrelmail language is not set to empty string
434 * use default squirrelmail language value from configuration.
436 if ((!$sm_language||
$default) &&
437 ! empty($squirrelmail_default_language)) {
438 $squirrelmail_language = $squirrelmail_default_language;
439 $sm_language = $squirrelmail_default_language;
442 /** provide failsafe language when detection fails */
443 if (! $sm_language) $sm_language='en_US';
445 $sm_notAlias = $sm_language;
447 // Catching removed translation
448 // System reverts to English translation if user prefs contain translation
449 // that is not available in $languages array
450 if (!isset($languages[$sm_notAlias])) {
451 $sm_notAlias="en_US";
454 while (isset($languages[$sm_notAlias]['ALIAS'])) {
455 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
458 if ( isset($sm_language) &&
460 $sm_language != '' &&
461 isset($languages[$sm_notAlias]['CHARSET']) ) {
462 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
463 sq_textdomain( 'squirrelmail' );
465 // Use LOCALE key, if it is set.
466 if (isset($languages[$sm_notAlias]['LOCALE'])){
467 $longlocale=$languages[$sm_notAlias]['LOCALE'];
469 $longlocale=$sm_notAlias;
472 // try setting locale
473 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
475 // check if locale is set and assign that locale to $longlocale
476 // in order to use it in putenv calls.
477 if (! is_bool($retlocale)) {
478 $longlocale=$retlocale;
479 } elseif (is_array($longlocale)) {
480 // setting of all locales failed.
481 // we need string instead of array used in LOCALE key.
482 $longlocale=$sm_notAlias;
485 if ( !((bool)ini_get('safe_mode')) &&
486 getenv( 'LC_ALL' ) != $longlocale ) {
487 putenv( "LC_ALL=$longlocale" );
488 putenv( "LANG=$longlocale" );
489 putenv( "LANGUAGE=$longlocale" );
490 putenv( "LC_NUMERIC=C" );
491 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
493 // Workaround for plugins that use numbers with floating point
494 // It might be removed if plugins use correct decimal delimiters
495 // according to locale settings.
496 setlocale(LC_NUMERIC
, 'C');
497 // Workaround for specific Turkish strtolower/strtoupper rules.
498 // Many functions expect English conversion rules.
499 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
502 * Set text direction/alignment variables
503 * When language environment is setup, scripts can use these globals
504 * without accessing $languages directly and making checks for optional
507 global $text_direction, $left_align, $right_align;
508 if (isset($languages[$sm_notAlias]['DIR']) &&
509 $languages[$sm_notAlias]['DIR'] == 'rtl') {
512 * @global string $text_direction
514 $text_direction='rtl';
517 * @global string $left_align
522 * @global string $right_align
526 $text_direction='ltr';
528 $right_align='right';
531 $squirrelmail_language = $sm_notAlias;
532 if ($squirrelmail_language == 'ja_JP') {
533 $oTemplate->header ('Content-Type: ' . $content_type . '; charset=EUC-JP');
534 if (!function_exists('mb_internal_encoding')) {
535 // Error messages can't be displayed here
537 // Revert to English if possible.
538 if (function_exists('setPref') && $username!='' && $data_dir!="") {
539 setPref($data_dir, $username, 'language', "en_US");
542 // stop further execution in order not to get php errors on mb_internal_encoding().
545 if (function_exists('mb_language')) {
546 mb_language('Japanese');
548 mb_internal_encoding('EUC-JP');
549 mb_http_output('pass');
550 } elseif ($squirrelmail_language == 'en_US') {
551 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $default_charset );
553 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $languages[$sm_notAlias]['CHARSET'] );
556 * mbstring.func_overload fix (#929644).
558 * php mbstring extension can replace standard string functions with their multibyte
559 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
560 * was added in php v.4.2.0
562 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
563 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
564 * interface can't trust regular string functions. Due to mbstring overloading design
565 * limits php scripts can't control this setting.
567 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
568 * to disable mbstring overloading. Japanese translation uses different internal encoding.
570 if ($squirrelmail_language != 'ja_JP' &&
571 function_exists('mb_internal_encoding') &&
572 check_php_version(4,2,0) &&
573 (int)ini_get('mbstring.func_overload')!=0) {
574 mb_internal_encoding('pass');
581 * Sets default_charset variable according to the one that is used by user's translations.
583 * Function changes global $default_charset variable in order to be sure, that it
584 * contains charset used by user's translation. Sanity of $squirrelmail_language
585 * and $default_charset combination is also tested.
587 * There can be a $default_charset setting in the
588 * config.php file, but the user may have a different language
589 * selected for a user interface. This function checks the
590 * language selected by the user and tags the outgoing messages
591 * with the appropriate charset corresponding to the language
592 * selection. This is "more right" (tm), than just stamping the
593 * message blindly with the system-wide $default_charset.
595 function set_my_charset(){
596 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
598 $my_language = getPref($data_dir, $username, 'language');
600 $my_language = $squirrelmail_language ;
602 // Catch removed translation
603 if (!isset($languages[$my_language])) {
604 $my_language="en_US";
606 while (isset($languages[$my_language]['ALIAS'])) {
607 $my_language = $languages[$my_language]['ALIAS'];
609 $my_charset = $languages[$my_language]['CHARSET'];
610 if ($my_language!='en_US') {
611 $default_charset = $my_charset;
616 * Replaces non-braking spaces inserted by some browsers with regular space
618 * This function can be used to replace non-braking space symbols
619 * that are inserted in forms by some browsers instead of normal
622 * @param string $string Text that needs to be cleaned
623 * @param string $charset Charset used in text
624 * @return string Cleaned text
626 function cleanup_nbsp($string,$charset) {
628 // reduce number of case statements
629 if (stristr('iso-8859-',substr($charset,0,9))){
630 $output_charset="iso-8859-x";
632 if (stristr('windows-125',substr($charset,0,11))){
633 $output_charset="cp125x";
635 if (stristr('koi8',substr($charset,0,4))){
636 $output_charset="koi8-x";
638 if (! isset($output_charset)){
639 $output_charset=strtolower($charset);
642 // where is non-braking space symbol
643 switch($output_charset):
656 // don't change string if charset is unmatched
660 // return space instead of non-braking space.
661 return str_replace($nbsp,' ',$string);
665 * Function informs if it is safe to convert given charset to the one that is used by user.
667 * It is safe to use conversion only if user uses utf-8 encoding and when
668 * converted charset is similar to the one that is used by user.
670 * @param string $input_charset Charset of text that needs to be converted
671 * @return bool is it possible to convert to user's charset
673 function is_conversion_safe($input_charset) {
674 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
676 if (isset($lossy_encoding) && $lossy_encoding )
679 // convert to lower case
680 $input_charset = strtolower($input_charset);
682 // Is user's locale Unicode based ?
683 if ( $default_charset == "utf-8" ) {
687 // Charsets that are similar
688 switch ($default_charset) {
690 if ( $input_charset == "iso-8859-5" ||
691 $input_charset == "koi8-r" ||
692 $input_charset == "koi8-u" ) {
698 if ( $input_charset == "iso-8859-13" ||
699 $input_charset == "iso-8859-4" ) {
705 if ( $input_charset == "iso-8859-13" ||
706 $input_charset == "windows-1257" ) {
712 if ( $input_charset == "windows-1251" ||
713 $input_charset == "koi8-r" ||
714 $input_charset == "koi8-u" ) {
720 if ( $input_charset == "iso-8859-4" ||
721 $input_charset == "windows-1257" ) {
727 if ( $input_charset == "windows-1251" ||
728 $input_charset == "iso-8859-5" ||
729 $input_charset == "koi8-u" ) {
735 if ( $input_charset == "windows-1251" ||
736 $input_charset == "iso-8859-5" ||
737 $input_charset == "koi8-r" ) {
748 * Converts html character entities to numeric entities
750 * SquirrelMail encoding functions work only with numeric entities.
751 * This function fixes issues with decoding functions that might convert
752 * some symbols to character entities. Issue is specific to PHP recode
753 * extension decoding. Function is used internally in charset_convert()
755 * @param string $str string that might contain html character entities
756 * @return string string with character entities converted to decimals.
759 function sqi18n_convert_entities($str) {
763 ' ' => ' ',
764 '¡' => '¡',
765 '¢' => '¢',
766 '£' => '£',
767 '¤' => '¤',
769 '¦' => '¦',
770 '§' => '§',
772 '©' => '©',
773 'ª' => 'ª',
774 '«' => '«',
778 '¯' => '¯',
780 '±' => '±',
781 '²' => '²',
782 '³' => '³',
783 '´' => '´',
784 'µ' => 'µ',
785 '¶' => '¶',
786 '·' => '·',
787 '¸' => '¸',
788 '¹' => '¹',
789 'º' => 'º',
790 '»' => '»',
791 '¼' => '¼',
792 '½' => '½',
793 '¾' => '¾',
794 '¿' => '¿',
795 'À' => 'À',
796 'Á' => 'Á',
797 'Â' => 'Â',
798 'Ã' => 'Ã',
799 'Ä' => 'Ä',
800 'Å' => 'Å',
801 'Æ' => 'Æ',
802 'Ç' => 'Ç',
803 'È' => 'È',
804 'É' => 'É',
805 'Ê' => 'Ê',
806 'Ë' => 'Ë',
807 'Ì' => 'Ì',
808 'Í' => 'Í',
809 'Î' => 'Î',
810 'Ï' => 'Ï',
812 'Ñ' => 'Ñ',
813 'Ò' => 'Ò',
814 'Ó' => 'Ó',
815 'Ô' => 'Ô',
816 'Õ' => 'Õ',
817 'Ö' => 'Ö',
818 '×' => '×',
819 'Ø' => 'Ø',
820 'Ù' => 'Ù',
821 'Ú' => 'Ú',
822 'Û' => 'Û',
823 'Ü' => 'Ü',
824 'Ý' => 'Ý',
825 'Þ' => 'Þ',
826 'ß' => 'ß',
827 'à' => 'à',
828 'á' => 'á',
829 'â' => 'â',
830 'ã' => 'ã',
831 'ä' => 'ä',
832 'å' => 'å',
833 'æ' => 'æ',
834 'ç' => 'ç',
835 'è' => 'è',
836 'é' => 'é',
837 'ê' => 'ê',
838 'ë' => 'ë',
839 'ì' => 'ì',
840 'í' => 'í',
841 'î' => 'î',
842 'ï' => 'ï',
844 'ñ' => 'ñ',
845 'ò' => 'ò',
846 'ó' => 'ó',
847 'ô' => 'ô',
848 'õ' => 'õ',
849 'ö' => 'ö',
850 '÷' => '÷',
851 'ø' => 'ø',
852 'ù' => 'ù',
853 'ú' => 'ú',
854 'û' => 'û',
855 'ü' => 'ü',
856 'ý' => 'ý',
857 'þ' => 'þ',
858 'ÿ' => 'ÿ',
860 'Œ' => 'Œ',
861 'œ' => 'œ',
862 'Š' => 'Š',
863 'š' => 'š',
864 'Ÿ' => 'Ÿ',
865 // Spacing Modifier Letters
866 'ˆ' => 'ˆ',
867 '˜' => '˜',
868 // General Punctuation
869 ' ' => ' ',
870 ' ' => ' ',
871 ' ' => ' ',
872 '‌' => '‌',
873 '‍' => '‍',
874 '‎' => '‎',
875 '‏' => '‏',
876 '–' => '–',
877 '—' => '—',
878 '‘' => '‘',
879 '’' => '’',
880 '‚' => '‚',
881 '“' => '“',
882 '”' => '”',
883 '„' => '„',
884 '†' => '†',
885 '‡' => '‡',
886 '‰' => '‰',
887 '‹' => '‹',
888 '›' => '›',
889 '€' => '€',
891 'ƒ' => 'ƒ',
893 'Α' => 'Α',
894 'Β' => 'Β',
895 'Γ' => 'Γ',
896 'Δ' => 'Δ',
897 'Ε' => 'Ε',
898 'Ζ' => 'Ζ',
900 'Θ' => 'Θ',
901 'Ι' => 'Ι',
902 'Κ' => 'Κ',
903 'Λ' => 'Λ',
907 'Ο' => 'Ο',
910 'Σ' => 'Σ',
912 'Υ' => 'Υ',
916 'Ω' => 'Ω',
917 'α' => 'α',
918 'β' => 'β',
919 'γ' => 'γ',
920 'δ' => 'δ',
921 'ε' => 'ε',
922 'ζ' => 'ζ',
924 'θ' => 'θ',
925 'ι' => 'ι',
926 'κ' => 'κ',
927 'λ' => 'λ',
931 'ο' => 'ο',
934 'ς' => 'ς',
935 'σ' => 'σ',
937 'υ' => 'υ',
941 'ω' => 'ω',
942 'ϑ' => 'ϑ',
943 'ϒ' => 'ϒ',
945 // General Punctuation
946 '•' => '•',
947 '…' => '…',
948 '′' => '′',
949 '″' => '″',
950 '‾' => '‾',
951 '⁄' => '⁄',
952 // Letterlike Symbols
953 '℘' => '℘',
954 'ℑ' => 'ℑ',
955 'ℜ' => 'ℜ',
956 '™' => '™',
957 'ℵ' => 'ℵ',
959 '←' => '←',
960 '↑' => '↑',
961 '→' => '→',
962 '↓' => '↓',
963 '↔' => '↔',
964 '↵' => '↵',
965 '⇐' => '⇐',
966 '⇑' => '⇑',
967 '⇒' => '⇒',
968 '⇓' => '⇓',
969 '⇔' => '⇔',
970 // Mathematical Operators
971 '∀' => '∀',
972 '∂' => '∂',
973 '∃' => '∃',
974 '∅' => '∅',
975 '∇' => '∇',
976 '∈' => '∈',
977 '∉' => '∉',
979 '∏' => '∏',
980 '∑' => '∑',
981 '−' => '−',
982 '∗' => '∗',
983 '√' => '√',
984 '∝' => '∝',
985 '∞' => '∞',
986 '∠' => '∠',
987 '∧' => '∧',
989 '∩' => '∩',
990 '∪' => '∪',
991 '∫' => '∫',
992 '∴' => '∴',
993 '∼' => '∼',
994 '≅' => '≅',
995 '≈' => '≈',
997 '≡' => '≡',
1000 '⊂' => '⊂',
1001 '⊃' => '⊃',
1002 '⊄' => '⊄',
1003 '⊆' => '⊆',
1004 '⊇' => '⊇',
1005 '⊕' => '⊕',
1006 '⊗' => '⊗',
1007 '⊥' => '⊥',
1008 '⋅' => '⋅',
1009 // Miscellaneous Technical
1010 '⌈' => '⌈',
1011 '⌉' => '⌉',
1012 '⌊' => '⌊',
1013 '⌋' => '⌋',
1014 '⟨' => '〈',
1015 '⟩' => '〉',
1017 '◊' => '◊',
1018 // Miscellaneous Symbols
1019 '♠' => '♠',
1020 '♣' => '♣',
1021 '♥' => '♥',
1022 '♦' => '♦');
1024 $str = str_replace(array_keys($entities), array_values($entities), $str);
1029 /* ------------------------------ main --------------------------- */
1031 global $squirrelmail_language, $languages, $use_gettext;
1033 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
1034 $squirrelmail_language = '';
1038 * Array specifies the available translations.
1040 * Structure of array:
1041 * $languages['language']['variable'] = 'value'
1043 * Possible 'variable' names:
1044 * NAME - Translation name in English
1045 * CHARSET - Encoding used by translation
1046 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
1047 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
1048 * 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
1049 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
1050 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
1052 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
1055 * @global array $languages
1057 $languages['en_US']['NAME'] = 'English';
1058 $languages['en_US']['CHARSET'] = 'iso-8859-1';
1059 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
1060 $languages['en']['ALIAS'] = 'en_US';
1063 * Automatic translation loading from setup.php files.
1064 * Solution for bug. 1240889.
1065 * setup.php file can contain $languages array entries and XTRA_CODE functions.
1067 if (is_dir(SM_PATH
. 'locale') &&
1068 is_readable(SM_PATH
. 'locale')) {
1069 $localedir = dir(SM_PATH
. 'locale');
1070 while($lang_dir=$localedir->read()) {
1071 // remove trailing slash, if present
1072 if (substr($lang_dir,-1)=='/') {
1073 $lang_dir = substr($lang_dir,0,-1);
1075 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
1076 $lang_dir != '.svn' && is_dir(SM_PATH
.'locale/'.$lang_dir) &&
1077 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
1078 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1081 $localedir->close();
1084 /* Detect whether gettext is installed. */
1086 if (function_exists('_')) {
1087 $gettext_flags +
= 1;
1089 if (function_exists('bindtextdomain')) {
1090 $gettext_flags +
= 2;
1092 if (function_exists('textdomain')) {
1093 $gettext_flags +
= 4;
1095 if (function_exists('ngettext')) {
1096 $gettext_flags +
= 8;
1099 /* If gettext is fully loaded, cool */
1100 if ($gettext_flags == 15) {
1101 $use_gettext = true;
1104 /* If ngettext support is missing, load it */
1105 elseif ($gettext_flags == 7) {
1106 $use_gettext = true;
1107 // load internal ngettext functions
1108 include_once(SM_PATH
. 'class/l10n.class.php');
1109 include_once(SM_PATH
. 'functions/ngettext.php');
1112 /* If we can fake gettext, try that */
1113 elseif ($gettext_flags == 0) {
1114 $use_gettext = true;
1115 include_once(SM_PATH
. 'functions/gettext.php');
1117 /* Uh-ho. A weird install */
1118 if (! $gettext_flags & 1) {
1120 * Function is used as replacement in broken installs
1127 if (! $gettext_flags & 2) {
1129 * Function is used as replacement in broken installs
1132 function bindtextdomain() {
1136 if (! $gettext_flags & 4) {
1138 * Function is used as replacemet in broken installs
1141 function textdomain() {
1145 if (! $gettext_flags & 8) {
1147 * Function is used as replacemet in broken installs
1150 function ngettext($str,$str2,$number) {
1158 if (! function_exists('dgettext')) {
1160 * Replacement for broken setups.
1163 function dgettext($domain,$str) {
1167 if (! function_exists('dngettext')) {
1169 * Replacement for broken setups
1172 function dngettext($domain,$str1,$strn,$number) {
1173 return ($number==1 ?
$str1 : $strn);