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.
18 * @copyright 1999-2014 The SquirrelMail Project Team
19 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
21 * @package squirrelmail
27 * Wrapper for textdomain(), bindtextdomain() and
28 * bind_textdomain_codeset() primarily intended for
29 * plugins when changing into their own text domain
32 * Note that if plugins using this function have
33 * their translation files located in the SquirrelMail
34 * locale directory, the second argument is optional.
36 * @param string $domain_name The name of the text domain
37 * (usually the plugin name, or
38 * "squirrelmail") being switched to.
39 * @param string $directory The directory that contains
40 * all translations for the domain
41 * (OPTIONAL; default is SquirrelMail
44 * @return string The name of the text domain that was set
45 * *BEFORE* it is changed herein - NOTE that
46 * this differs from PHP's textdomain()
48 * @since 1.4.10 and 1.5.2
50 function sq_change_text_domain($domain_name, $directory='') {
51 global $gettext_domain;
52 static $domains_already_seen = array();
54 $return_value = $gettext_domain;
56 // empty domain defaults to "squirrelmail"
58 if (empty($domain_name)) $domain_name = 'squirrelmail';
60 // only need to call bindtextdomain() once
62 if (in_array($domain_name, $domains_already_seen)) {
63 sq_textdomain($domain_name);
67 $domains_already_seen[] = $domain_name;
69 if (empty($directory)) $directory = SM_PATH
. 'locale/';
71 sq_bindtextdomain($domain_name, $directory);
72 sq_textdomain($domain_name);
78 * Gettext bindtextdomain wrapper.
80 * Wrapper solves differences between php versions in order to provide
81 * ngettext support. Should be used if translation uses ngettext
84 * This also provides a bind_textdomain_codeset call to make sure the
85 * domain's encoding will not be overridden.
87 * @since 1.4.10 and 1.5.1
88 * @param string $domain gettext domain name
89 * @param string $dir directory that contains all translations (OPTIONAL;
90 * if not specified, defaults to SquirrelMail locale
92 * @return string path to translation directory
94 function sq_bindtextdomain($domain,$dir='') {
95 global $l10n, $gettext_flags, $sm_notAlias;
97 if (empty($dir)) $dir = SM_PATH
. 'locale/';
99 if ($gettext_flags==7) {
100 // gettext extension without ngettext
101 if (substr($dir, -1) != '/') $dir .= '/';
102 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
103 $input = new FileReader($mofile);
104 $l10n[$domain] = new gettext_reader($input);
107 $dir=bindtextdomain($domain,$dir);
109 // set codeset in order to avoid gettext charset conversions
110 if (function_exists('bind_textdomain_codeset')
111 && isset($languages[$sm_notAlias]['CHARSET'])) {
113 // Japanese translation uses different internal charset
114 if ($sm_notAlias == 'ja_JP') {
115 bind_textdomain_codeset ($domain_name, 'EUC-JP');
117 bind_textdomain_codeset ($domain_name, $languages[$sm_notAlias]['CHARSET']);
126 * Gettext textdomain wrapper.
127 * Makes sure that gettext_domain global is modified.
129 * @param string $name gettext domain name
130 * @return string gettext domain name
132 function sq_textdomain($domain) {
133 global $gettext_domain;
134 $gettext_domain=textdomain($domain);
135 return $gettext_domain;
139 * php setlocale function wrapper
141 * From php 4.3.0 it is possible to use arrays in order to set locale.
142 * php gettext extension works only when locale is set. This wrapper
143 * function allows to use more than one locale name.
145 * @param int $category locale category name. Use php named constants
146 * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME)
147 * @param mixed $locale option contains array with possible locales or string with one locale
148 * @return string name of set locale or false, if all locales fail.
149 * @since 1.4.5 and 1.5.1
150 * @see http://php.net/setlocale
152 function sq_setlocale($category,$locale) {
153 if (is_string($locale)) {
154 // string with only one locale
155 $ret = setlocale($category,$locale);
156 } elseif (! check_php_version(4,3)) {
157 // older php version (second setlocale argument must be string)
160 while ( ! $ret && $index<count($locale)) {
161 $ret=setlocale($category,$locale[$index]);
165 // php 4.3.0 or better, use entire array
166 $ret=setlocale($category,$locale);
170 if (preg_match("/^.*\/.*\/.*\/.*\/.*\/.*$/",$ret)) {
172 * Welcome to We-Don't-Follow-Own-Fine-Manual department
173 * OpenBSD 3.8, 3.9-current and maybe later versions
174 * return invalid response to setlocale command.
175 * SM bug report #1427512.
183 * Converts string from given charset to charset, that can be displayed by user translation.
185 * Function by default returns html encoded strings, if translation uses different encoding.
186 * If Japanese translation is used - function returns string converted to euc-jp
187 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
188 * If $charset is not supported - function returns unconverted string.
190 * sanitizing of html tags is also done by this function.
192 * @param string $charset
193 * @param string $string Text to be decoded
194 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
195 * Argument is available since 1.4.5 and 1.5.1.
196 * @param boolean $save_html disables sm_encode_html_special_chars() in order to preserve
197 * html formating. Use with care. Available since 1.4.6 and 1.5.1
198 * @return string decoded string
200 function charset_decode ($charset, $string, $force_decode=false, $save_html=false) {
201 global $languages, $squirrelmail_language, $default_charset;
202 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
204 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
205 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
206 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
209 $charset = strtolower($charset);
213 // Variables that allow to use functions without function_exist() calls
214 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
215 $use_php_recode=false; }
216 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
217 $use_php_iconv=false; }
219 // Don't do conversion if charset is the same.
220 if ( ! $force_decode && $charset == strtolower($default_charset) )
221 return ($save_html ?
$string : sm_encode_html_special_chars($string));
223 // catch iso-8859-8-i thing
224 if ( $charset == "iso-8859-8-i" )
225 $charset = "iso-8859-8";
228 * Recode converts html special characters automatically if you use
229 * 'charset..html' decoding. There is no documented way to put -d option
230 * into php recode function call.
232 if ( $use_php_recode ) {
233 if ( $default_charset == "utf-8" ) {
234 // other charsets can be converted to utf-8 without loss.
235 // and output string is smaller
236 $string = recode_string($charset . "..utf-8",$string);
237 return ($save_html ?
$string : sm_encode_html_special_chars($string));
239 $string = recode_string($charset . "..html",$string);
240 // recode does not convert single quote, sm_encode_html_special_chars does.
241 $string = str_replace("'", ''', $string);
242 // undo html specialchars
244 $string=str_replace(array('&','"','<','>'),
245 array('&','"','<','>'),$string);
250 // iconv functions does not have html target and can be used only with utf-8
251 if ( $use_php_iconv && $default_charset=='utf-8') {
252 $string = iconv($charset,$default_charset,$string);
253 return ($save_html ?
$string : sm_encode_html_special_chars($string));
256 // If we don't use recode and iconv, we'll do it old way.
258 /* All HTML special characters are 7 bit and can be replaced first */
259 if (! $save_html) $string = sm_encode_html_special_chars ($string);
261 /* controls cpu and memory intensive decoding cycles */
262 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
263 $aggressive_decoding=false; }
265 $decode=fixcharset($charset);
266 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
267 if ($decode != 'index' && file_exists($decodefile)) {
268 include_once($decodefile);
269 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
270 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
278 * Converts html string to given charset
279 * @since 1.4.4 and 1.5.1
280 * @param string $string
281 * @param string $charset
282 * @param boolean $htmlencode keep sm_encode_html_special_chars encoding
285 function charset_encode($string,$charset,$htmlencode=true) {
286 global $default_charset;
288 $encode=fixcharset($charset);
289 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
290 if ($encode != 'index' && file_exists($encodefile)) {
291 include_once($encodefile);
292 $ret = call_user_func('charset_encode_'.$encode, $string);
293 } elseif(file_exists(SM_PATH
. 'functions/encode/us_ascii.php')) {
294 // function replaces all 8bit html entities with question marks.
295 // it is used when other encoding functions are unavailable
296 include_once(SM_PATH
. 'functions/encode/us_ascii.php');
297 $ret = charset_encode_us_ascii($string);
300 * fix for yahoo users that remove all us-ascii related things
306 * Undo html special chars, some places (like compose form) have
307 * own sanitizing functions and don't need html symbols.
308 * Undo chars only after encoding in order to prevent conversion of
309 * html entities in plain text emails.
311 if (! $htmlencode ) {
312 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
318 * Combined decoding and encoding functions
320 * If conversion is done to charset different that utf-8, unsupported symbols
321 * will be replaced with question marks.
322 * @since 1.4.4 and 1.5.1
323 * @param string $in_charset initial charset
324 * @param string $string string that has to be converted
325 * @param string $out_charset final charset
326 * @param boolean $htmlencode keep sm_encode_html_special_chars encoding
327 * @return string converted string
329 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
330 $string=charset_decode($in_charset,$string,true);
331 $string=sqi18n_convert_entities($string);
332 $string=charset_encode($string,$out_charset,$htmlencode);
337 * Makes charset name suitable for decoding cycles
339 * ks_c_5601_1987, x-euc-* and x-windows-* charsets are supported
340 * since 1.4.6 and 1.5.1.
342 * @since 1.4.4 and 1.5.0
343 * @param string $charset Name of charset
344 * @return string $charset Adjusted name of charset
346 function fixcharset($charset) {
348 /* Remove minus and characters that might be used in paths from charset
349 * name in order to be able to use it in function names and include calls.
350 * Also make sure it's in lower case (ala "UTF" --> "utf")
352 $charset=preg_replace("/[-:.\/\\\]/",'_', strtolower($charset));
354 // OE ks_c_5601_1987 > cp949
355 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
356 // Moz x-euc-tw > euc-tw
357 $charset=str_replace('x_euc','euc',$charset);
358 // Moz x-windows-949 > cp949
359 $charset=str_replace('x_windows_','cp',$charset);
361 // windows-125x and cp125x charsets
362 $charset=str_replace('windows_','cp',$charset);
365 $charset=str_replace('ibm','cp',$charset);
367 // iso-8859-8-i -> iso-8859-8
368 // use same cycle until I'll find differences
369 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
375 * Set up the language to be output
376 * if $do_search is true, then scan the browser information
377 * for a possible language that we know
379 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
380 * gettext translation bindings and html header information.
382 * Function returns error codes, if there is some fatal error.
384 * 1 = mbstring support is not present,
385 * 2 = mbstring support is not present, user's translation reverted to en_US.
387 * @param string $sm_language Translation used by user's interface
388 * @param bool $do_search Use browser's preferred language detection functions.
390 * @param bool $default Set $sm_language to $squirrelmail_default_language if
391 * language detection fails or language is not set.
393 * @param string $content_type The content type being served currently (OPTIONAL;
394 * if not specified, defaults to whatever the template
395 * set that is in use has defined).
396 * @return int function execution error codes.
399 function set_up_language($sm_language, $do_search = false, $default = false,
400 $content_type = '') {
402 static $SetupAlready = 0;
403 global $use_gettext, $languages, $squirrelmail_language,
404 $squirrelmail_default_language, $default_charset, $sm_notAlias,
405 $username, $data_dir, $oTemplate;
411 $SetupAlready = TRUE;
412 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
414 // grab content type if needed
416 if (empty($content_type)) $content_type = $oTemplate->get_content_type();
419 * If function is asked to detect preferred language
420 * OR SquirrelMail default language is set to empty string
422 * SquirrelMail language ($sm_language) is empty string
423 * (not set in user's prefs and no cookie with language info)
425 * browser provides list of preferred languages
427 * get preferred language from HTTP_ACCEPT_LANGUAGE header
429 if (($do_search ||
empty($squirrelmail_default_language)) &&
431 isset($accept_lang)) {
432 // TODO: use more than one language, if first language is not available
433 // FIXME: function assumes that string contains two or more characters.
434 // FIXME: some languages use 5 chars
435 $sm_language = substr($accept_lang, 0, 2);
439 * If language preference is not set OR script asks to use default language
441 * default SquirrelMail language is not set to empty string
443 * use default SquirrelMail language value from configuration.
445 if ((!$sm_language||
$default) &&
446 ! empty($squirrelmail_default_language)) {
447 $squirrelmail_language = $squirrelmail_default_language;
448 $sm_language = $squirrelmail_default_language;
451 /** provide failsafe language when detection fails */
452 if (! $sm_language) $sm_language='en_US';
454 $sm_notAlias = $sm_language;
456 // Catching removed translation
457 // System reverts to English translation if user prefs contain translation
458 // that is not available in $languages array
459 if (!isset($languages[$sm_notAlias])) {
460 $sm_notAlias="en_US";
463 while (isset($languages[$sm_notAlias]['ALIAS'])) {
464 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
467 if ( isset($sm_language) &&
469 $sm_language != '' &&
470 isset($languages[$sm_notAlias]['CHARSET']) ) {
471 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
472 sq_textdomain( 'squirrelmail' );
474 // Use LOCALE key, if it is set.
475 if (isset($languages[$sm_notAlias]['LOCALE'])){
476 $longlocale=$languages[$sm_notAlias]['LOCALE'];
478 $longlocale=$sm_notAlias;
481 // try setting locale
482 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
484 // check if locale is set and assign that locale to $longlocale
485 // in order to use it in putenv calls.
486 if (! is_bool($retlocale)) {
487 $longlocale=$retlocale;
488 } elseif (is_array($longlocale)) {
489 // setting of all locales failed.
490 // we need string instead of array used in LOCALE key.
491 $longlocale=$sm_notAlias;
494 if ( !((bool)ini_get('safe_mode')) &&
495 getenv( 'LC_ALL' ) != $longlocale ) {
496 putenv( "LC_ALL=$longlocale" );
497 putenv( "LANG=$longlocale" );
498 putenv( "LANGUAGE=$longlocale" );
499 putenv( "LC_NUMERIC=C" );
500 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
502 // Workaround for plugins that use numbers with floating point
503 // It might be removed if plugins use correct decimal delimiters
504 // according to locale settings.
505 setlocale(LC_NUMERIC
, 'C');
506 // Workaround for specific Turkish strtolower/strtoupper rules.
507 // Many functions expect English conversion rules.
508 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
511 * Set text direction/alignment variables
512 * When language environment is setup, scripts can use these globals
513 * without accessing $languages directly and making checks for optional
516 global $text_direction, $left_align, $right_align;
517 if (isset($languages[$sm_notAlias]['DIR']) &&
518 $languages[$sm_notAlias]['DIR'] == 'rtl') {
521 * @global string $text_direction
523 $text_direction='rtl';
526 * @global string $left_align
531 * @global string $right_align
535 $text_direction='ltr';
537 $right_align='right';
540 $squirrelmail_language = $sm_notAlias;
541 if ($squirrelmail_language == 'ja_JP') {
542 $oTemplate->header ('Content-Type: ' . $content_type . '; charset=EUC-JP');
543 if (!function_exists('mb_internal_encoding')) {
544 // Error messages can't be displayed here
546 // Revert to English if possible.
547 if (function_exists('setPref') && $username!='' && $data_dir!="") {
548 setPref($data_dir, $username, 'language', "en_US");
551 // stop further execution in order not to get php errors on mb_internal_encoding().
554 if (function_exists('mb_language')) {
555 mb_language('Japanese');
557 mb_internal_encoding('EUC-JP');
558 mb_http_output('pass');
559 } elseif ($squirrelmail_language == 'en_US') {
560 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $default_charset );
562 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $languages[$sm_notAlias]['CHARSET'] );
565 * mbstring.func_overload fix (#929644).
567 * php mbstring extension can replace standard string functions with their multibyte
568 * equivalents. See http://php.net/ref.mbstring#mbstring.overload. This feature
569 * was added in php v.4.2.0
571 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
572 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
573 * interface can't trust regular string functions. Due to mbstring overloading design
574 * limits php scripts can't control this setting.
576 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
577 * to disable mbstring overloading. Japanese translation uses different internal encoding.
579 if ($squirrelmail_language != 'ja_JP' &&
580 function_exists('mb_internal_encoding') &&
581 check_php_version(4,2,0) &&
582 (int)ini_get('mbstring.func_overload')!=0) {
583 mb_internal_encoding('pass');
590 * Sets default_charset variable according to the one that is used by user's
593 * Function changes global $default_charset variable in order to be sure, that
594 * it contains charset used by user's translation. Sanity of
595 * $squirrelmail_language and $default_charset combination provided in the
596 * SquirrelMail configuration is also tested.
598 * There can be a $default_charset setting in the
599 * config.php file, but the user may have a different language
600 * selected for a user interface. This function checks the
601 * language selected by the user and tags the outgoing messages
602 * with the appropriate charset corresponding to the language
603 * selection. This is "more right" (tm), than just stamping the
604 * message blindly with the system-wide $default_charset.
606 function set_my_charset(){
607 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
609 $my_language = getPref($data_dir, $username, 'language');
611 $my_language = $squirrelmail_language ;
613 // Catch removed translation
614 if (!isset($languages[$my_language])) {
615 $my_language="en_US";
617 while (isset($languages[$my_language]['ALIAS'])) {
618 $my_language = $languages[$my_language]['ALIAS'];
620 $my_charset = $languages[$my_language]['CHARSET'];
621 if ($my_language!='en_US') {
622 $default_charset = $my_charset;
627 * Replaces non-braking spaces inserted by some browsers with regular space
629 * This function can be used to replace non-braking space symbols
630 * that are inserted in forms by some browsers instead of normal
633 * @param string $string Text that needs to be cleaned
634 * @param string $charset Charset used in text
635 * @return string Cleaned text
637 function cleanup_nbsp($string,$charset) {
639 // reduce number of case statements
640 if (stristr('iso-8859-',substr($charset,0,9))){
641 $output_charset="iso-8859-x";
643 if (stristr('windows-125',substr($charset,0,11))){
644 $output_charset="cp125x";
646 if (stristr('koi8',substr($charset,0,4))){
647 $output_charset="koi8-x";
649 if (! isset($output_charset)){
650 $output_charset=strtolower($charset);
653 // where is non-braking space symbol
654 switch($output_charset):
667 // don't change string if charset is unmatched
671 // return space instead of non-braking space.
672 return str_replace($nbsp,' ',$string);
676 * Function informs if it is safe to convert given charset to the one that is used by user.
678 * It is safe to use conversion only if user uses utf-8 encoding and when
679 * converted charset is similar to the one that is used by user.
681 * @param string $input_charset Charset of text that needs to be converted
682 * @return bool is it possible to convert to user's charset
684 function is_conversion_safe($input_charset) {
685 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
687 if (isset($lossy_encoding) && $lossy_encoding )
690 // convert to lower case
691 $input_charset = strtolower($input_charset);
693 // Is user's locale Unicode based ?
694 if ( $default_charset == "utf-8" ) {
698 // Charsets that are similar
699 switch ($default_charset) {
701 if ( $input_charset == "iso-8859-5" ||
702 $input_charset == "koi8-r" ||
703 $input_charset == "koi8-u" ) {
709 if ( $input_charset == "iso-8859-13" ||
710 $input_charset == "iso-8859-4" ) {
716 if ( $input_charset == "iso-8859-13" ||
717 $input_charset == "windows-1257" ) {
723 if ( $input_charset == "windows-1251" ||
724 $input_charset == "koi8-r" ||
725 $input_charset == "koi8-u" ) {
731 if ( $input_charset == "iso-8859-4" ||
732 $input_charset == "windows-1257" ) {
738 if ( $input_charset == "windows-1251" ||
739 $input_charset == "iso-8859-5" ||
740 $input_charset == "koi8-u" ) {
746 if ( $input_charset == "windows-1251" ||
747 $input_charset == "iso-8859-5" ||
748 $input_charset == "koi8-r" ) {
759 * Converts html character entities to numeric entities
761 * SquirrelMail encoding functions work only with numeric entities.
762 * This function fixes issues with decoding functions that might convert
763 * some symbols to character entities. Issue is specific to PHP recode
764 * extension decoding. Function is used internally in charset_convert()
766 * @param string $str string that might contain html character entities
767 * @return string string with character entities converted to decimals.
770 function sqi18n_convert_entities($str) {
774 ' ' => ' ',
775 '¡' => '¡',
776 '¢' => '¢',
777 '£' => '£',
778 '¤' => '¤',
780 '¦' => '¦',
781 '§' => '§',
783 '©' => '©',
784 'ª' => 'ª',
785 '«' => '«',
789 '¯' => '¯',
791 '±' => '±',
792 '²' => '²',
793 '³' => '³',
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 'Ï' => 'Ï',
823 'Ñ' => 'Ñ',
824 'Ò' => 'Ò',
825 'Ó' => 'Ó',
826 'Ô' => 'Ô',
827 'Õ' => 'Õ',
828 'Ö' => 'Ö',
829 '×' => '×',
830 'Ø' => 'Ø',
831 'Ù' => 'Ù',
832 'Ú' => 'Ú',
833 'Û' => 'Û',
834 'Ü' => 'Ü',
835 'Ý' => 'Ý',
836 'Þ' => 'Þ',
837 'ß' => 'ß',
838 'à' => 'à',
839 'á' => 'á',
840 'â' => 'â',
841 'ã' => 'ã',
842 'ä' => 'ä',
843 'å' => 'å',
844 'æ' => 'æ',
845 'ç' => 'ç',
846 'è' => 'è',
847 'é' => 'é',
848 'ê' => 'ê',
849 'ë' => 'ë',
850 'ì' => 'ì',
851 'í' => 'í',
852 'î' => 'î',
853 'ï' => 'ï',
855 'ñ' => 'ñ',
856 'ò' => 'ò',
857 'ó' => 'ó',
858 'ô' => 'ô',
859 'õ' => 'õ',
860 'ö' => 'ö',
861 '÷' => '÷',
862 'ø' => 'ø',
863 'ù' => 'ù',
864 'ú' => 'ú',
865 'û' => 'û',
866 'ü' => 'ü',
867 'ý' => 'ý',
868 'þ' => 'þ',
869 'ÿ' => 'ÿ',
871 'Œ' => 'Œ',
872 'œ' => 'œ',
873 'Š' => 'Š',
874 'š' => 'š',
875 'Ÿ' => 'Ÿ',
876 // Spacing Modifier Letters
877 'ˆ' => 'ˆ',
878 '˜' => '˜',
879 // General Punctuation
880 ' ' => ' ',
881 ' ' => ' ',
882 ' ' => ' ',
883 '‌' => '‌',
884 '‍' => '‍',
885 '‎' => '‎',
886 '‏' => '‏',
887 '–' => '–',
888 '—' => '—',
889 '‘' => '‘',
890 '’' => '’',
891 '‚' => '‚',
892 '“' => '“',
893 '”' => '”',
894 '„' => '„',
895 '†' => '†',
896 '‡' => '‡',
897 '‰' => '‰',
898 '‹' => '‹',
899 '›' => '›',
900 '€' => '€',
902 'ƒ' => 'ƒ',
904 'Α' => 'Α',
905 'Β' => 'Β',
906 'Γ' => 'Γ',
907 'Δ' => 'Δ',
908 'Ε' => 'Ε',
909 'Ζ' => 'Ζ',
911 'Θ' => 'Θ',
912 'Ι' => 'Ι',
913 'Κ' => 'Κ',
914 'Λ' => 'Λ',
918 'Ο' => 'Ο',
921 'Σ' => 'Σ',
923 'Υ' => 'Υ',
927 'Ω' => 'Ω',
928 'α' => 'α',
929 'β' => 'β',
930 'γ' => 'γ',
931 'δ' => 'δ',
932 'ε' => 'ε',
933 'ζ' => 'ζ',
935 'θ' => 'θ',
936 'ι' => 'ι',
937 'κ' => 'κ',
938 'λ' => 'λ',
942 'ο' => 'ο',
945 'ς' => 'ς',
946 'σ' => 'σ',
948 'υ' => 'υ',
952 'ω' => 'ω',
953 'ϑ' => 'ϑ',
954 'ϒ' => 'ϒ',
956 // General Punctuation
957 '•' => '•',
958 '…' => '…',
959 '′' => '′',
960 '″' => '″',
961 '‾' => '‾',
962 '⁄' => '⁄',
963 // Letterlike Symbols
964 '℘' => '℘',
965 'ℑ' => 'ℑ',
966 'ℜ' => 'ℜ',
967 '™' => '™',
968 'ℵ' => 'ℵ',
970 '←' => '←',
971 '↑' => '↑',
972 '→' => '→',
973 '↓' => '↓',
974 '↔' => '↔',
975 '↵' => '↵',
976 '⇐' => '⇐',
977 '⇑' => '⇑',
978 '⇒' => '⇒',
979 '⇓' => '⇓',
980 '⇔' => '⇔',
981 // Mathematical Operators
982 '∀' => '∀',
983 '∂' => '∂',
984 '∃' => '∃',
985 '∅' => '∅',
986 '∇' => '∇',
987 '∈' => '∈',
988 '∉' => '∉',
990 '∏' => '∏',
991 '∑' => '∑',
992 '−' => '−',
993 '∗' => '∗',
994 '√' => '√',
995 '∝' => '∝',
996 '∞' => '∞',
997 '∠' => '∠',
998 '∧' => '∧',
1000 '∩' => '∩',
1001 '∪' => '∪',
1002 '∫' => '∫',
1003 '∴' => '∴',
1004 '∼' => '∼',
1005 '≅' => '≅',
1006 '≈' => '≈',
1007 '≠' => '≠',
1008 '≡' => '≡',
1009 '≤' => '≤',
1010 '≥' => '≥',
1011 '⊂' => '⊂',
1012 '⊃' => '⊃',
1013 '⊄' => '⊄',
1014 '⊆' => '⊆',
1015 '⊇' => '⊇',
1016 '⊕' => '⊕',
1017 '⊗' => '⊗',
1018 '⊥' => '⊥',
1019 '⋅' => '⋅',
1020 // Miscellaneous Technical
1021 '⌈' => '⌈',
1022 '⌉' => '⌉',
1023 '⌊' => '⌊',
1024 '⌋' => '⌋',
1025 '⟨' => '〈',
1026 '⟩' => '〉',
1028 '◊' => '◊',
1029 // Miscellaneous Symbols
1030 '♠' => '♠',
1031 '♣' => '♣',
1032 '♥' => '♥',
1033 '♦' => '♦');
1035 $str = str_replace(array_keys($entities), array_values($entities), $str);
1040 /* ------------------------------ main --------------------------- */
1042 global $squirrelmail_language, $languages, $use_gettext;
1044 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
1045 $squirrelmail_language = '';
1049 * This array specifies the available translations.
1051 * Structure of array:
1052 * $languages['language']['variable'] = 'value'
1054 * Possible 'variable' names:
1055 * NAME - Translation name in English
1056 * CHARSET - Encoding used by translation
1057 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
1058 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
1059 * 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
1060 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
1061 * XTRA_CODE - translation uses special functions. See http://squirrelmail.org/docs/devel/devel-3.html
1063 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
1066 * @global array $languages
1068 $languages['en_US']['NAME'] = 'English';
1069 $languages['en_US']['CHARSET'] = 'iso-8859-1';
1070 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
1071 $languages['en']['ALIAS'] = 'en_US';
1074 * Automatic translation loading from setup.php files.
1075 * Solution for bug. 1240889.
1076 * setup.php file can contain $languages array entries and XTRA_CODE functions.
1078 if (is_dir(SM_PATH
. 'locale') &&
1079 is_readable(SM_PATH
. 'locale')) {
1080 $localedir = dir(SM_PATH
. 'locale');
1081 while($lang_dir=$localedir->read()) {
1082 // remove trailing slash, if present
1083 if (substr($lang_dir,-1)=='/') {
1084 $lang_dir = substr($lang_dir,0,-1);
1086 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
1087 $lang_dir != '.svn' && is_dir(SM_PATH
.'locale/'.$lang_dir) &&
1088 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
1089 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1092 $localedir->close();
1095 /* Detect whether gettext is installed. */
1097 if (function_exists('_')) {
1098 $gettext_flags +
= 1;
1100 if (function_exists('bindtextdomain')) {
1101 $gettext_flags +
= 2;
1103 if (function_exists('textdomain')) {
1104 $gettext_flags +
= 4;
1106 if (function_exists('ngettext')) {
1107 $gettext_flags +
= 8;
1110 /* If gettext is fully loaded, cool */
1111 if ($gettext_flags == 15) {
1112 $use_gettext = true;
1115 /* If ngettext support is missing, load it */
1116 elseif ($gettext_flags == 7) {
1117 $use_gettext = true;
1118 // load internal ngettext functions
1119 include_once(SM_PATH
. 'class/l10n.class.php');
1120 include_once(SM_PATH
. 'functions/ngettext.php');
1123 /* If we can fake gettext, try that */
1124 elseif ($gettext_flags == 0) {
1125 $use_gettext = true;
1126 include_once(SM_PATH
. 'functions/gettext.php');
1128 /* Uh-ho. A weird install */
1129 if (! $gettext_flags & 1) {
1131 * Function is used as replacement in broken installs
1138 if (! $gettext_flags & 2) {
1140 * Function is used as replacement in broken installs
1143 function bindtextdomain() {
1147 if (! $gettext_flags & 4) {
1149 * Function is used as replacemet in broken installs
1152 function textdomain() {
1156 if (! $gettext_flags & 8) {
1158 * Function is used as replacemet in broken installs
1161 function ngettext($str,$str2,$number) {
1169 if (! function_exists('dgettext')) {
1171 * Replacement for broken setups.
1174 function dgettext($domain,$str) {
1178 if (! function_exists('dngettext')) {
1180 * Replacement for broken setups
1183 function dngettext($domain,$str1,$strn,$number) {
1184 return ($number==1 ?
$str1 : $strn);