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 // empty domain defaults to "squirrelmail"
57 if (empty($domain_name)) $domain_name = 'squirrelmail';
59 // only need to call bindtextdomain() once
61 if (in_array($domain_name, $domains_already_seen)) {
62 sq_textdomain($domain_name);
66 $domains_already_seen[] = $domain_name;
68 if (empty($directory)) $directory = SM_PATH
. 'locale/';
70 sq_bindtextdomain($domain_name, $directory);
71 sq_textdomain($domain_name);
77 * Gettext bindtextdomain wrapper.
79 * Wrapper solves differences between php versions in order to provide
80 * ngettext support. Should be used if translation uses ngettext
83 * This also provides a bind_textdomain_codeset call to make sure the
84 * domain's encoding will not be overridden.
86 * @since 1.4.10 and 1.5.1
87 * @param string $domain gettext domain name
88 * @param string $dir directory that contains all translations (OPTIONAL;
89 * if not specified, defaults to SquirrelMail locale
91 * @return string path to translation directory
93 function sq_bindtextdomain($domain,$dir='') {
94 global $l10n, $gettext_flags, $sm_notAlias;
96 if (empty($dir)) $dir = SM_PATH
. 'locale/';
98 if ($gettext_flags==7) {
99 // gettext extension without ngettext
100 if (substr($dir, -1) != '/') $dir .= '/';
101 $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo';
102 $input = new FileReader($mofile);
103 $l10n[$domain] = new gettext_reader($input);
106 $dir=bindtextdomain($domain,$dir);
108 // set codeset in order to avoid gettext charset conversions
109 if (function_exists('bind_textdomain_codeset')
110 && isset($languages[$sm_notAlias]['CHARSET'])) {
112 // Japanese translation uses different internal charset
113 if ($sm_notAlias == 'ja_JP') {
114 bind_textdomain_codeset ($domain_name, 'EUC-JP');
116 bind_textdomain_codeset ($domain_name, $languages[$sm_notAlias]['CHARSET']);
125 * Gettext textdomain wrapper.
126 * Makes sure that gettext_domain global is modified.
128 * @param string $name gettext domain name
129 * @return string gettext domain name
131 function sq_textdomain($domain) {
132 global $gettext_domain;
133 $gettext_domain=textdomain($domain);
134 return $gettext_domain;
138 * php setlocale function wrapper
140 * From php 4.3.0 it is possible to use arrays in order to set locale.
141 * php gettext extension works only when locale is set. This wrapper
142 * function allows to use more than one locale name.
144 * @param int $category locale category name. Use php named constants
145 * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME)
146 * @param mixed $locale option contains array with possible locales or string with one locale
147 * @return string name of set locale or false, if all locales fail.
148 * @since 1.5.1 and 1.4.5
149 * @see http://www.php.net/setlocale
151 function sq_setlocale($category,$locale) {
152 if (is_string($locale)) {
153 // string with only one locale
154 $ret = setlocale($category,$locale);
155 } elseif (! check_php_version(4,3)) {
156 // older php version (second setlocale argument must be string)
159 while ( ! $ret && $index<count($locale)) {
160 $ret=setlocale($category,$locale[$index]);
164 // php 4.3.0 or better, use entire array
165 $ret=setlocale($category,$locale);
169 if (preg_match("/^.*\/.*\/.*\/.*\/.*\/.*$/",$ret)) {
171 * Welcome to We-Don't-Follow-Own-Fine-Manual department
172 * OpenBSD 3.8, 3.9-current and maybe later versions
173 * return invalid response to setlocale command.
174 * SM bug report #1427512.
182 * Converts string from given charset to charset, that can be displayed by user translation.
184 * Function by default returns html encoded strings, if translation uses different encoding.
185 * If Japanese translation is used - function returns string converted to euc-jp
186 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
187 * If $charset is not supported - function returns unconverted string.
189 * sanitizing of html tags is also done by this function.
191 * @param string $charset
192 * @param string $string Text to be decoded
193 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
194 * Argument is available since 1.5.1 and 1.4.5.
195 * @param boolean $save_html disables htmlspecialchars() in order to preserve
196 * html formating. Use with care. Available since 1.5.1
197 * @return string decoded string
199 function charset_decode ($charset, $string, $force_decode=false, $save_html=false) {
200 global $languages, $squirrelmail_language, $default_charset;
201 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
203 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
204 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
205 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
208 $charset = strtolower($charset);
212 // Variables that allow to use functions without function_exist() calls
213 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
214 $use_php_recode=false; }
215 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
216 $use_php_iconv=false; }
218 // Don't do conversion if charset is the same.
219 if ( ! $force_decode && $charset == strtolower($default_charset) )
220 return ($save_html ?
$string : htmlspecialchars($string));
222 // catch iso-8859-8-i thing
223 if ( $charset == "iso-8859-8-i" )
224 $charset = "iso-8859-8";
227 * Recode converts html special characters automatically if you use
228 * 'charset..html' decoding. There is no documented way to put -d option
229 * into php recode function call.
231 if ( $use_php_recode ) {
232 if ( $default_charset == "utf-8" ) {
233 // other charsets can be converted to utf-8 without loss.
234 // and output string is smaller
235 $string = recode_string($charset . "..utf-8",$string);
236 return ($save_html ?
$string : htmlspecialchars($string));
238 $string = recode_string($charset . "..html",$string);
239 // recode does not convert single quote, htmlspecialchars does.
240 $string = str_replace("'", ''', $string);
241 // undo html specialchars
243 $string=str_replace(array('&','"','<','>'),
244 array('&','"','<','>'),$string);
249 // iconv functions does not have html target and can be used only with utf-8
250 if ( $use_php_iconv && $default_charset=='utf-8') {
251 $string = iconv($charset,$default_charset,$string);
252 return ($save_html ?
$string : htmlspecialchars($string));
255 // If we don't use recode and iconv, we'll do it old way.
257 /* All HTML special characters are 7 bit and can be replaced first */
258 if (! $save_html) $string = htmlspecialchars ($string);
260 /* controls cpu and memory intensive decoding cycles */
261 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
262 $aggressive_decoding=false; }
264 $decode=fixcharset($charset);
265 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
266 if ($decode != 'index' && file_exists($decodefile)) {
267 include_once($decodefile);
268 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
269 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
277 * Converts html string to given charset
278 * @since 1.5.1 and 1.4.4
279 * @param string $string
280 * @param string $charset
281 * @param boolean $htmlencode keep htmlspecialchars encoding
284 function charset_encode($string,$charset,$htmlencode=true) {
285 global $default_charset;
287 $encode=fixcharset($charset);
288 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
289 if ($encode != 'index' && file_exists($encodefile)) {
290 include_once($encodefile);
291 $ret = call_user_func('charset_encode_'.$encode, $string);
292 } elseif(file_exists(SM_PATH
. 'functions/encode/us_ascii.php')) {
293 // function replaces all 8bit html entities with question marks.
294 // it is used when other encoding functions are unavailable
295 include_once(SM_PATH
. 'functions/encode/us_ascii.php');
296 $ret = charset_encode_us_ascii($string);
299 * fix for yahoo users that remove all us-ascii related things
305 * Undo html special chars, some places (like compose form) have
306 * own sanitizing functions and don't need html symbols.
307 * Undo chars only after encoding in order to prevent conversion of
308 * html entities in plain text emails.
310 if (! $htmlencode ) {
311 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
317 * Combined decoding and encoding functions
319 * If conversion is done to charset different that utf-8, unsupported symbols
320 * will be replaced with question marks.
321 * @since 1.5.1 and 1.4.4
322 * @param string $in_charset initial charset
323 * @param string $string string that has to be converted
324 * @param string $out_charset final charset
325 * @param boolean $htmlencode keep htmlspecialchars encoding
326 * @return string converted string
328 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
329 $string=charset_decode($in_charset,$string,true);
330 $string=sqi18n_convert_entities($string);
331 $string=charset_encode($string,$out_charset,$htmlencode);
336 * Makes charset name suitable for decoding cycles
338 * @since 1.5.0 and 1.4.4
339 * @param string $charset Name of charset
340 * @return string $charset Adjusted name of charset
342 function fixcharset($charset) {
343 /* remove minus and characters that might be used in paths from charset
344 * name in order to be able to use it in function names and include calls.
346 $charset=preg_replace("/[-:.\/\\\]/",'_',$charset);
348 // OE ks_c_5601_1987 > cp949
349 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
350 // Moz x-euc-tw > euc-tw
351 $charset=str_replace('x_euc','euc',$charset);
352 // Moz x-windows-949 > cp949
353 $charset=str_replace('x_windows_','cp',$charset);
355 // windows-125x and cp125x charsets
356 $charset=str_replace('windows_','cp',$charset);
359 $charset=str_replace('ibm','cp',$charset);
361 // iso-8859-8-i -> iso-8859-8
362 // use same cycle until I'll find differences
363 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
369 * Set up the language to be output
370 * if $do_search is true, then scan the browser information
371 * for a possible language that we know
373 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
374 * gettext translation bindings and html header information.
376 * Function returns error codes, if there is some fatal error.
378 * 1 = mbstring support is not present,
379 * 2 = mbstring support is not present, user's translation reverted to en_US.
381 * @param string $sm_language Translation used by user's interface
382 * @param bool $do_search Use browser's preferred language detection functions.
384 * @param bool $default Set $sm_language to $squirrelmail_default_language if
385 * language detection fails or language is not set.
387 * @param string $content_type The content type being served currently (OPTIONAL;
388 * if not specified, defaults to whatever the template
389 * set that is in use has defined).
391 * @return int function execution error codes.
394 function set_up_language($sm_language, $do_search=false,
395 $default=false, $content_type='') {
397 static $SetupAlready = 0;
398 global $use_gettext, $languages, $oTemplate,
399 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
400 $sm_notAlias, $username, $data_dir;
406 $SetupAlready = TRUE;
407 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
409 // grab content type if needed
411 if (empty($content_type)) $content_type = $oTemplate->get_content_type();
414 * If function is asked to detect preferred language
415 * OR squirrelmail default language is set to empty string
417 * squirrelmail language ($sm_language) is empty string
418 * (not set in user's prefs and no cookie with language info)
420 * browser provides list of preferred languages
422 * get preferred language from HTTP_ACCEPT_LANGUAGE header
424 if (($do_search ||
empty($squirrelmail_default_language)) &&
426 isset($accept_lang)) {
427 // TODO: use more than one language, if first language is not available
428 // FIXME: function assumes that string contains two or more characters.
429 // FIXME: some languages use 5 chars
430 $sm_language = substr($accept_lang, 0, 2);
434 * If language preference is not set OR script asks to use default language
436 * default squirrelmail language is not set to empty string
438 * use default squirrelmail language value from configuration.
440 if ((!$sm_language||
$default) &&
441 ! empty($squirrelmail_default_language)) {
442 $squirrelmail_language = $squirrelmail_default_language;
443 $sm_language = $squirrelmail_default_language;
446 /** provide failsafe language when detection fails */
447 if (! $sm_language) $sm_language='en_US';
449 $sm_notAlias = $sm_language;
451 // Catching removed translation
452 // System reverts to English translation if user prefs contain translation
453 // that is not available in $languages array
454 if (!isset($languages[$sm_notAlias])) {
455 $sm_notAlias="en_US";
458 while (isset($languages[$sm_notAlias]['ALIAS'])) {
459 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
462 if ( isset($sm_language) &&
464 $sm_language != '' &&
465 isset($languages[$sm_notAlias]['CHARSET']) ) {
466 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
467 sq_textdomain( 'squirrelmail' );
469 // Use LOCALE key, if it is set.
470 if (isset($languages[$sm_notAlias]['LOCALE'])){
471 $longlocale=$languages[$sm_notAlias]['LOCALE'];
473 $longlocale=$sm_notAlias;
476 // try setting locale
477 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
479 // check if locale is set and assign that locale to $longlocale
480 // in order to use it in putenv calls.
481 if (! is_bool($retlocale)) {
482 $longlocale=$retlocale;
483 } elseif (is_array($longlocale)) {
484 // setting of all locales failed.
485 // we need string instead of array used in LOCALE key.
486 $longlocale=$sm_notAlias;
489 if ( !((bool)ini_get('safe_mode')) &&
490 getenv( 'LC_ALL' ) != $longlocale ) {
491 putenv( "LC_ALL=$longlocale" );
492 putenv( "LANG=$longlocale" );
493 putenv( "LANGUAGE=$longlocale" );
494 putenv( "LC_NUMERIC=C" );
495 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
497 // Workaround for plugins that use numbers with floating point
498 // It might be removed if plugins use correct decimal delimiters
499 // according to locale settings.
500 setlocale(LC_NUMERIC
, 'C');
501 // Workaround for specific Turkish strtolower/strtoupper rules.
502 // Many functions expect English conversion rules.
503 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
506 * Set text direction/alignment variables
507 * When language environment is setup, scripts can use these globals
508 * without accessing $languages directly and making checks for optional
511 global $text_direction, $left_align, $right_align;
512 if (isset($languages[$sm_notAlias]['DIR']) &&
513 $languages[$sm_notAlias]['DIR'] == 'rtl') {
516 * @global string $text_direction
518 $text_direction='rtl';
521 * @global string $left_align
526 * @global string $right_align
530 $text_direction='ltr';
532 $right_align='right';
535 $squirrelmail_language = $sm_notAlias;
536 if ($squirrelmail_language == 'ja_JP') {
537 $oTemplate->header ('Content-Type: ' . $content_type . '; charset=EUC-JP');
538 if (!function_exists('mb_internal_encoding')) {
539 // Error messages can't be displayed here
541 // Revert to English if possible.
542 if (function_exists('setPref') && $username!='' && $data_dir!="") {
543 setPref($data_dir, $username, 'language', "en_US");
546 // stop further execution in order not to get php errors on mb_internal_encoding().
549 if (function_exists('mb_language')) {
550 mb_language('Japanese');
552 mb_internal_encoding('EUC-JP');
553 mb_http_output('pass');
554 } elseif ($squirrelmail_language == 'en_US') {
555 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $default_charset );
557 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $languages[$sm_notAlias]['CHARSET'] );
560 * mbstring.func_overload fix (#929644).
562 * php mbstring extension can replace standard string functions with their multibyte
563 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
564 * was added in php v.4.2.0
566 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
567 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
568 * interface can't trust regular string functions. Due to mbstring overloading design
569 * limits php scripts can't control this setting.
571 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
572 * to disable mbstring overloading. Japanese translation uses different internal encoding.
574 if ($squirrelmail_language != 'ja_JP' &&
575 function_exists('mb_internal_encoding') &&
576 check_php_version(4,2,0) &&
577 (int)ini_get('mbstring.func_overload')!=0) {
578 mb_internal_encoding('pass');
585 * Sets default_charset variable according to the one that is used by user's translations.
587 * Function changes global $default_charset variable in order to be sure, that it
588 * contains charset used by user's translation. Sanity of $squirrelmail_language
589 * and $default_charset combination is also tested.
591 * There can be a $default_charset setting in the
592 * config.php file, but the user may have a different language
593 * selected for a user interface. This function checks the
594 * language selected by the user and tags the outgoing messages
595 * with the appropriate charset corresponding to the language
596 * selection. This is "more right" (tm), than just stamping the
597 * message blindly with the system-wide $default_charset.
599 function set_my_charset(){
600 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
602 $my_language = getPref($data_dir, $username, 'language');
604 $my_language = $squirrelmail_language ;
606 // Catch removed translation
607 if (!isset($languages[$my_language])) {
608 $my_language="en_US";
610 while (isset($languages[$my_language]['ALIAS'])) {
611 $my_language = $languages[$my_language]['ALIAS'];
613 $my_charset = $languages[$my_language]['CHARSET'];
614 if ($my_language!='en_US') {
615 $default_charset = $my_charset;
620 * Replaces non-braking spaces inserted by some browsers with regular space
622 * This function can be used to replace non-braking space symbols
623 * that are inserted in forms by some browsers instead of normal
626 * @param string $string Text that needs to be cleaned
627 * @param string $charset Charset used in text
628 * @return string Cleaned text
630 function cleanup_nbsp($string,$charset) {
632 // reduce number of case statements
633 if (stristr('iso-8859-',substr($charset,0,9))){
634 $output_charset="iso-8859-x";
636 if (stristr('windows-125',substr($charset,0,11))){
637 $output_charset="cp125x";
639 if (stristr('koi8',substr($charset,0,4))){
640 $output_charset="koi8-x";
642 if (! isset($output_charset)){
643 $output_charset=strtolower($charset);
646 // where is non-braking space symbol
647 switch($output_charset):
660 // don't change string if charset is unmatched
664 // return space instead of non-braking space.
665 return str_replace($nbsp,' ',$string);
669 * Function informs if it is safe to convert given charset to the one that is used by user.
671 * It is safe to use conversion only if user uses utf-8 encoding and when
672 * converted charset is similar to the one that is used by user.
674 * @param string $input_charset Charset of text that needs to be converted
675 * @return bool is it possible to convert to user's charset
677 function is_conversion_safe($input_charset) {
678 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
680 if (isset($lossy_encoding) && $lossy_encoding )
683 // convert to lower case
684 $input_charset = strtolower($input_charset);
686 // Is user's locale Unicode based ?
687 if ( $default_charset == "utf-8" ) {
691 // Charsets that are similar
692 switch ($default_charset) {
694 if ( $input_charset == "iso-8859-5" ||
695 $input_charset == "koi8-r" ||
696 $input_charset == "koi8-u" ) {
702 if ( $input_charset == "iso-8859-13" ||
703 $input_charset == "iso-8859-4" ) {
709 if ( $input_charset == "iso-8859-13" ||
710 $input_charset == "windows-1257" ) {
716 if ( $input_charset == "windows-1251" ||
717 $input_charset == "koi8-r" ||
718 $input_charset == "koi8-u" ) {
724 if ( $input_charset == "iso-8859-4" ||
725 $input_charset == "windows-1257" ) {
731 if ( $input_charset == "windows-1251" ||
732 $input_charset == "iso-8859-5" ||
733 $input_charset == "koi8-u" ) {
739 if ( $input_charset == "windows-1251" ||
740 $input_charset == "iso-8859-5" ||
741 $input_charset == "koi8-r" ) {
752 * Converts html character entities to numeric entities
754 * SquirrelMail encoding functions work only with numeric entities.
755 * This function fixes issues with decoding functions that might convert
756 * some symbols to character entities. Issue is specific to PHP recode
757 * extension decoding. Function is used internally in charset_convert()
759 * @param string $str string that might contain html character entities
760 * @return string string with character entities converted to decimals.
763 function sqi18n_convert_entities($str) {
767 ' ' => ' ',
768 '¡' => '¡',
769 '¢' => '¢',
770 '£' => '£',
771 '¤' => '¤',
773 '¦' => '¦',
774 '§' => '§',
776 '©' => '©',
777 'ª' => 'ª',
778 '«' => '«',
782 '¯' => '¯',
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 'Ë' => 'Ë',
811 'Ì' => 'Ì',
812 'Í' => 'Í',
813 'Î' => 'Î',
814 'Ï' => 'Ï',
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 'ë' => 'ë',
843 'ì' => 'ì',
844 'í' => 'í',
845 'î' => 'î',
846 'ï' => 'ï',
848 'ñ' => 'ñ',
849 'ò' => 'ò',
850 'ó' => 'ó',
851 'ô' => 'ô',
852 'õ' => 'õ',
853 'ö' => 'ö',
854 '÷' => '÷',
855 'ø' => 'ø',
856 'ù' => 'ù',
857 'ú' => 'ú',
858 'û' => 'û',
859 'ü' => 'ü',
860 'ý' => 'ý',
861 'þ' => 'þ',
862 'ÿ' => 'ÿ',
864 'Œ' => 'Œ',
865 'œ' => 'œ',
866 'Š' => 'Š',
867 'š' => 'š',
868 'Ÿ' => 'Ÿ',
869 // Spacing Modifier Letters
870 'ˆ' => 'ˆ',
871 '˜' => '˜',
872 // General Punctuation
873 ' ' => ' ',
874 ' ' => ' ',
875 ' ' => ' ',
876 '‌' => '‌',
877 '‍' => '‍',
878 '‎' => '‎',
879 '‏' => '‏',
880 '–' => '–',
881 '—' => '—',
882 '‘' => '‘',
883 '’' => '’',
884 '‚' => '‚',
885 '“' => '“',
886 '”' => '”',
887 '„' => '„',
888 '†' => '†',
889 '‡' => '‡',
890 '‰' => '‰',
891 '‹' => '‹',
892 '›' => '›',
893 '€' => '€',
895 'ƒ' => 'ƒ',
897 'Α' => 'Α',
898 'Β' => 'Β',
899 'Γ' => 'Γ',
900 'Δ' => 'Δ',
901 'Ε' => 'Ε',
902 'Ζ' => 'Ζ',
904 'Θ' => 'Θ',
905 'Ι' => 'Ι',
906 'Κ' => 'Κ',
907 'Λ' => 'Λ',
911 'Ο' => 'Ο',
914 'Σ' => 'Σ',
916 'Υ' => 'Υ',
920 'Ω' => 'Ω',
921 'α' => 'α',
922 'β' => 'β',
923 'γ' => 'γ',
924 'δ' => 'δ',
925 'ε' => 'ε',
926 'ζ' => 'ζ',
928 'θ' => 'θ',
929 'ι' => 'ι',
930 'κ' => 'κ',
931 'λ' => 'λ',
935 'ο' => 'ο',
938 'ς' => 'ς',
939 'σ' => 'σ',
941 'υ' => 'υ',
945 'ω' => 'ω',
946 'ϑ' => 'ϑ',
947 'ϒ' => 'ϒ',
949 // General Punctuation
950 '•' => '•',
951 '…' => '…',
952 '′' => '′',
953 '″' => '″',
954 '‾' => '‾',
955 '⁄' => '⁄',
956 // Letterlike Symbols
957 '℘' => '℘',
958 'ℑ' => 'ℑ',
959 'ℜ' => 'ℜ',
960 '™' => '™',
961 'ℵ' => 'ℵ',
963 '←' => '←',
964 '↑' => '↑',
965 '→' => '→',
966 '↓' => '↓',
967 '↔' => '↔',
968 '↵' => '↵',
969 '⇐' => '⇐',
970 '⇑' => '⇑',
971 '⇒' => '⇒',
972 '⇓' => '⇓',
973 '⇔' => '⇔',
974 // Mathematical Operators
975 '∀' => '∀',
976 '∂' => '∂',
977 '∃' => '∃',
978 '∅' => '∅',
979 '∇' => '∇',
980 '∈' => '∈',
981 '∉' => '∉',
983 '∏' => '∏',
984 '∑' => '∑',
985 '−' => '−',
986 '∗' => '∗',
987 '√' => '√',
988 '∝' => '∝',
989 '∞' => '∞',
990 '∠' => '∠',
991 '∧' => '∧',
993 '∩' => '∩',
994 '∪' => '∪',
995 '∫' => '∫',
996 '∴' => '∴',
997 '∼' => '∼',
998 '≅' => '≅',
999 '≈' => '≈',
1000 '≠' => '≠',
1001 '≡' => '≡',
1002 '≤' => '≤',
1003 '≥' => '≥',
1004 '⊂' => '⊂',
1005 '⊃' => '⊃',
1006 '⊄' => '⊄',
1007 '⊆' => '⊆',
1008 '⊇' => '⊇',
1009 '⊕' => '⊕',
1010 '⊗' => '⊗',
1011 '⊥' => '⊥',
1012 '⋅' => '⋅',
1013 // Miscellaneous Technical
1014 '⌈' => '⌈',
1015 '⌉' => '⌉',
1016 '⌊' => '⌊',
1017 '⌋' => '⌋',
1018 '⟨' => '〈',
1019 '⟩' => '〉',
1021 '◊' => '◊',
1022 // Miscellaneous Symbols
1023 '♠' => '♠',
1024 '♣' => '♣',
1025 '♥' => '♥',
1026 '♦' => '♦');
1028 $str = str_replace(array_keys($entities), array_values($entities), $str);
1033 /* ------------------------------ main --------------------------- */
1035 global $squirrelmail_language, $languages, $use_gettext;
1037 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
1038 $squirrelmail_language = '';
1042 * Array specifies the available translations.
1044 * Structure of array:
1045 * $languages['language']['variable'] = 'value'
1047 * Possible 'variable' names:
1048 * NAME - Translation name in English
1049 * CHARSET - Encoding used by translation
1050 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
1051 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
1052 * 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
1053 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
1054 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
1056 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
1059 * @global array $languages
1061 $languages['en_US']['NAME'] = 'English';
1062 $languages['en_US']['CHARSET'] = 'iso-8859-1';
1063 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
1064 $languages['en']['ALIAS'] = 'en_US';
1067 * Automatic translation loading from setup.php files.
1068 * Solution for bug. 1240889.
1069 * setup.php file can contain $languages array entries and XTRA_CODE functions.
1071 if (is_dir(SM_PATH
. 'locale') &&
1072 is_readable(SM_PATH
. 'locale')) {
1073 $localedir = dir(SM_PATH
. 'locale');
1074 while($lang_dir=$localedir->read()) {
1075 // remove trailing slash, if present
1076 if (substr($lang_dir,-1)=='/') {
1077 $lang_dir = substr($lang_dir,0,-1);
1079 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
1080 $lang_dir != '.svn' && is_dir(SM_PATH
.'locale/'.$lang_dir) &&
1081 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
1082 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1085 $localedir->close();
1088 /* Detect whether gettext is installed. */
1090 if (function_exists('_')) {
1091 $gettext_flags +
= 1;
1093 if (function_exists('bindtextdomain')) {
1094 $gettext_flags +
= 2;
1096 if (function_exists('textdomain')) {
1097 $gettext_flags +
= 4;
1099 if (function_exists('ngettext')) {
1100 $gettext_flags +
= 8;
1103 /* If gettext is fully loaded, cool */
1104 if ($gettext_flags == 15) {
1105 $use_gettext = true;
1108 /* If ngettext support is missing, load it */
1109 elseif ($gettext_flags == 7) {
1110 $use_gettext = true;
1111 // load internal ngettext functions
1112 include_once(SM_PATH
. 'class/l10n.class.php');
1113 include_once(SM_PATH
. 'functions/ngettext.php');
1116 /* If we can fake gettext, try that */
1117 elseif ($gettext_flags == 0) {
1118 $use_gettext = true;
1119 include_once(SM_PATH
. 'functions/gettext.php');
1121 /* Uh-ho. A weird install */
1122 if (! $gettext_flags & 1) {
1124 * Function is used as replacement in broken installs
1131 if (! $gettext_flags & 2) {
1133 * Function is used as replacement in broken installs
1136 function bindtextdomain() {
1140 if (! $gettext_flags & 4) {
1142 * Function is used as replacemet in broken installs
1145 function textdomain() {
1149 if (! $gettext_flags & 8) {
1151 * Function is used as replacemet in broken installs
1154 function ngettext($str,$str2,$number) {
1162 if (! function_exists('dgettext')) {
1164 * Replacement for broken setups.
1167 function dgettext($domain,$str) {
1171 if (! function_exists('dngettext')) {
1173 * Replacement for broken setups
1176 function dngettext($domain,$str1,$strn,$number) {
1177 return ($number==1 ?
$str1 : $strn);