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-2022 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 a string from the given $charset to a character set that
184 * can be displayed by the current user interface language (translation)
186 * Function by default returns html encoded strings if translation uses
187 * different encoding.
188 * If Japanese translation is used - function returns string converted to euc-jp
189 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
190 * If $charset is not supported - function returns unconverted string.
192 * sanitizing of html tags is also done by this function.
194 * @param string $charset The charset of the incoming string
195 * @param string $string Text to be decoded
196 * @param boolean $force_decode converts string to html without $charset!=$default_charset check.
197 * Argument is available since 1.4.5 and 1.5.1.
198 * @param boolean $save_html disables sm_encode_html_special_chars() in order to preserve
199 * html formating. Use with care. Available since 1.4.6 and 1.5.1
200 * @return string decoded string
202 function charset_decode ($charset, $string, $force_decode=false, $save_html=false) {
203 global $languages, $squirrelmail_language, $default_charset;
204 global $use_php_recode, $use_php_iconv, $aggressive_decoding;
206 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
207 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
208 $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string);
211 $charset = strtolower($charset);
215 // Variables that allow to use functions without function_exist() calls
216 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
217 $use_php_recode=false; }
218 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
219 $use_php_iconv=false; }
221 // Don't do conversion if charset is the same.
222 if ( ! $force_decode && $charset == strtolower($default_charset) )
223 return ($save_html ?
$string : sm_encode_html_special_chars($string, ENT_COMPAT
, $charset));
225 // catch iso-8859-8-i thing
226 if ( $charset == "iso-8859-8-i" )
227 $charset = "iso-8859-8";
230 * Recode converts html special characters automatically if you use
231 * 'charset..html' decoding. There is no documented way to put -d option
232 * into php recode function call.
234 if ( $use_php_recode ) {
235 if ( $default_charset == "utf-8" ) {
236 // other charsets can be converted to utf-8 without loss.
237 // and output string is smaller
238 $string = recode_string($charset . "..utf-8",$string);
239 return ($save_html ?
$string : sm_encode_html_special_chars($string, ENT_COMPAT
, $charset));
241 $string = recode_string($charset . "..html",$string);
242 // recode does not convert single quote, sm_encode_html_special_chars does.
243 $string = str_replace("'", ''', $string);
244 // undo html specialchars
246 $string=str_replace(array('&','"','<','>'),
247 array('&','"','<','>'),$string);
252 // iconv functions does not have html target and can be used only with utf-8
253 if ( $use_php_iconv && $default_charset=='utf-8') {
254 $string = iconv($charset,$default_charset,$string);
255 return ($save_html ?
$string : sm_encode_html_special_chars($string, ENT_COMPAT
, $charset));
258 // If we don't use recode and iconv, we'll do it old way.
260 /* All HTML special characters are 7 bit and can be replaced first */
261 if (! $save_html) $string = sm_encode_html_special_chars($string, ENT_COMPAT
, $charset);
263 /* controls cpu and memory intensive decoding cycles */
264 if (! isset($aggressive_decoding) ||
$aggressive_decoding=="" ) {
265 $aggressive_decoding=false; }
267 $decode=fixcharset($charset);
268 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
269 if ($decode != 'index' && file_exists($decodefile)) {
270 include_once($decodefile);
271 // send $save_html argument to decoding function. needed for iso-2022-xx decoding.
272 $ret = call_user_func('charset_decode_'.$decode, $string, $save_html);
280 * Converts html string to given charset
281 * @since 1.4.4 and 1.5.1
282 * @param string $string
283 * @param string $charset
284 * @param boolean $htmlencode keep sm_encode_html_special_chars encoding
287 function charset_encode($string,$charset,$htmlencode=true) {
288 global $default_charset;
290 $encode=fixcharset($charset);
291 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
292 if ($encode != 'index' && file_exists($encodefile)) {
293 include_once($encodefile);
294 $ret = call_user_func('charset_encode_'.$encode, $string);
295 } elseif(file_exists(SM_PATH
. 'functions/encode/us_ascii.php')) {
296 // function replaces all 8bit html entities with question marks.
297 // it is used when other encoding functions are unavailable
298 include_once(SM_PATH
. 'functions/encode/us_ascii.php');
299 $ret = charset_encode_us_ascii($string);
302 * fix for yahoo users that remove all us-ascii related things
308 * Undo html special chars, some places (like compose form) have
309 * own sanitizing functions and don't need html symbols.
310 * Undo chars only after encoding in order to prevent conversion of
311 * html entities in plain text emails.
313 if (! $htmlencode ) {
314 $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret);
320 * Combined decoding and encoding functions
322 * If conversion is done to charset different that utf-8, unsupported symbols
323 * will be replaced with question marks.
324 * @since 1.4.4 and 1.5.1
325 * @param string $in_charset initial charset
326 * @param string $string string that has to be converted
327 * @param string $out_charset final charset
328 * @param boolean $htmlencode keep sm_encode_html_special_chars encoding
329 * @return string converted string
331 function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) {
332 $string=charset_decode($in_charset,$string,true);
333 $string=sqi18n_convert_entities($string);
334 $string=charset_encode($string,$out_charset,$htmlencode);
339 * Makes charset name suitable for decoding cycles
341 * ks_c_5601_1987, x-euc-* and x-windows-* charsets are supported
342 * since 1.4.6 and 1.5.1.
344 * @since 1.4.4 and 1.5.0
345 * @param string $charset Name of charset
346 * @return string $charset Adjusted name of charset
348 function fixcharset($charset) {
350 /* Remove minus and characters that might be used in paths from charset
351 * name in order to be able to use it in function names and include calls.
352 * Also make sure it's in lower case (ala "UTF" --> "utf")
354 $charset=preg_replace("/[-:.\/\\\]/",'_', strtolower($charset));
356 // OE ks_c_5601_1987 > cp949
357 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
358 // Moz x-euc-tw > euc-tw
359 $charset=str_replace('x_euc','euc',$charset);
360 // Moz x-windows-949 > cp949
361 $charset=str_replace('x_windows_','cp',$charset);
363 // windows-125x and cp125x charsets
364 $charset=str_replace('windows_','cp',$charset);
367 $charset=str_replace('ibm','cp',$charset);
369 // iso-8859-8-i -> iso-8859-8
370 // use same cycle until I'll find differences
371 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
377 * Set up the language to be output
378 * if $do_search is true, then scan the browser information
379 * for a possible language that we know
381 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
382 * gettext translation bindings and html header information.
384 * Function returns error codes, if there is some fatal error.
386 * 1 = mbstring support is not present,
387 * 2 = mbstring support is not present, user's translation reverted to en_US.
389 * @param string $sm_language Translation used by user's interface
390 * @param bool $do_search Use browser's preferred language detection functions.
392 * @param bool $default Set $sm_language to $squirrelmail_default_language if
393 * language detection fails or language is not set.
395 * @param string $content_type The content type being served currently (OPTIONAL;
396 * if not specified, defaults to whatever the template
397 * set that is in use has defined).
398 * @return int function execution error codes.
401 function set_up_language($sm_language, $do_search = false, $default = false,
402 $content_type = '') {
404 static $SetupAlready = 0;
405 global $use_gettext, $languages, $squirrelmail_language,
406 $squirrelmail_default_language, $default_charset, $sm_notAlias,
407 $username, $data_dir, $oTemplate;
413 $SetupAlready = TRUE;
414 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
416 // grab content type if needed
418 if (empty($content_type)) $content_type = $oTemplate->get_content_type();
421 * If function is asked to detect preferred language
422 * OR SquirrelMail default language is set to empty string
424 * SquirrelMail language ($sm_language) is empty string
425 * (not set in user's prefs and no cookie with language info)
427 * browser provides list of preferred languages
429 * get preferred language from HTTP_ACCEPT_LANGUAGE header
431 if (($do_search ||
empty($squirrelmail_default_language)) &&
433 isset($accept_lang)) {
434 // TODO: use more than one language, if first language is not available
435 // FIXME: function assumes that string contains two or more characters.
436 // FIXME: some languages use 5 chars
437 $sm_language = substr($accept_lang, 0, 2);
441 * If language preference is not set OR script asks to use default language
443 * default SquirrelMail language is not set to empty string
445 * use default SquirrelMail language value from configuration.
447 if ((!$sm_language||
$default) &&
448 ! empty($squirrelmail_default_language)) {
449 $squirrelmail_language = $squirrelmail_default_language;
450 $sm_language = $squirrelmail_default_language;
453 /** provide failsafe language when detection fails */
454 if (! $sm_language) $sm_language='en_US';
456 $sm_notAlias = $sm_language;
458 // Catching removed translation
459 // System reverts to English translation if user prefs contain translation
460 // that is not available in $languages array
461 if (!isset($languages[$sm_notAlias])) {
462 $sm_notAlias="en_US";
465 while (isset($languages[$sm_notAlias]['ALIAS'])) {
466 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
469 if ( isset($sm_language) &&
471 $sm_language != '' &&
472 isset($languages[$sm_notAlias]['CHARSET']) ) {
473 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
474 sq_textdomain( 'squirrelmail' );
476 // Use LOCALE key, if it is set.
477 if (isset($languages[$sm_notAlias]['LOCALE'])){
478 $longlocale=$languages[$sm_notAlias]['LOCALE'];
480 $longlocale=$sm_notAlias;
483 // try setting locale
484 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
486 // check if locale is set and assign that locale to $longlocale
487 // in order to use it in putenv calls.
488 if (! is_bool($retlocale)) {
489 $longlocale=$retlocale;
490 } elseif (is_array($longlocale)) {
491 // setting of all locales failed.
492 // we need string instead of array used in LOCALE key.
493 $longlocale=$sm_notAlias;
496 if ( !((bool)ini_get('safe_mode')) &&
497 getenv( 'LC_ALL' ) != $longlocale ) {
498 putenv( "LC_ALL=$longlocale" );
499 putenv( "LANG=$longlocale" );
500 putenv( "LANGUAGE=$longlocale" );
501 putenv( "LC_NUMERIC=C" );
502 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
504 // Workaround for plugins that use numbers with floating point
505 // It might be removed if plugins use correct decimal delimiters
506 // according to locale settings.
507 setlocale(LC_NUMERIC
, 'C');
508 // Workaround for specific Turkish strtolower/strtoupper rules.
509 // Many functions expect English conversion rules.
510 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
513 * Set text direction/alignment variables
514 * When language environment is setup, scripts can use these globals
515 * without accessing $languages directly and making checks for optional
518 global $text_direction, $left_align, $right_align;
519 if (isset($languages[$sm_notAlias]['DIR']) &&
520 $languages[$sm_notAlias]['DIR'] == 'rtl') {
523 * @global string $text_direction
525 $text_direction='rtl';
528 * @global string $left_align
533 * @global string $right_align
537 $text_direction='ltr';
539 $right_align='right';
542 $squirrelmail_language = $sm_notAlias;
543 if ($squirrelmail_language == 'ja_JP') {
544 $oTemplate->header ('Content-Type: ' . $content_type . '; charset=EUC-JP');
545 if (!function_exists('mb_internal_encoding')) {
546 // Error messages can't be displayed here
548 // Revert to English if possible.
549 if (function_exists('setPref') && $username!='' && $data_dir!="") {
550 setPref($data_dir, $username, 'language', "en_US");
553 // stop further execution in order not to get php errors on mb_internal_encoding().
556 if (function_exists('mb_language')) {
557 mb_language('Japanese');
559 mb_internal_encoding('EUC-JP');
560 mb_http_output('pass');
561 } elseif ($squirrelmail_language == 'en_US') {
562 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $default_charset );
564 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $languages[$sm_notAlias]['CHARSET'] );
567 * mbstring.func_overload fix (#929644).
569 * php mbstring extension can replace standard string functions with their multibyte
570 * equivalents. See http://php.net/ref.mbstring#mbstring.overload. This feature
571 * was added in php v.4.2.0
573 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
574 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
575 * interface can't trust regular string functions. Due to mbstring overloading design
576 * limits php scripts can't control this setting.
578 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
579 * to disable mbstring overloading. Japanese translation uses different internal encoding.
581 if ($squirrelmail_language != 'ja_JP' &&
582 function_exists('mb_internal_encoding') &&
583 check_php_version(4,2,0) &&
584 (int)ini_get('mbstring.func_overload')!=0) {
585 mb_internal_encoding('pass');
592 * Sets default_charset variable according to the one that is used by user's
595 * Function changes global $default_charset variable in order to be sure, that
596 * it contains charset used by user's translation. Sanity of
597 * $squirrelmail_language and $default_charset combination provided in the
598 * SquirrelMail configuration is also tested.
600 * There can be a $default_charset setting in the
601 * config.php file, but the user may have a different language
602 * selected for a user interface. This function checks the
603 * language selected by the user and tags the outgoing messages
604 * with the appropriate charset corresponding to the language
605 * selection. This is "more right" (tm), than just stamping the
606 * message blindly with the system-wide $default_charset.
608 function set_my_charset(){
609 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
611 $my_language = getPref($data_dir, $username, 'language');
613 $my_language = $squirrelmail_language ;
615 // Catch removed translation
616 if (!isset($languages[$my_language])) {
617 $my_language="en_US";
619 while (isset($languages[$my_language]['ALIAS'])) {
620 $my_language = $languages[$my_language]['ALIAS'];
622 $my_charset = $languages[$my_language]['CHARSET'];
623 if ($my_language!='en_US') {
624 $default_charset = $my_charset;
629 * Replaces non-braking spaces inserted by some browsers with regular space
631 * This function can be used to replace non-braking space symbols
632 * that are inserted in forms by some browsers instead of normal
635 * @param string $string Text that needs to be cleaned
636 * @param string $charset Charset used in text
637 * @return string Cleaned text
639 function cleanup_nbsp($string,$charset) {
641 // reduce number of case statements
642 if (stristr('iso-8859-',substr($charset,0,9))){
643 $output_charset="iso-8859-x";
645 if (stristr('windows-125',substr($charset,0,11))){
646 $output_charset="cp125x";
648 if (stristr('koi8',substr($charset,0,4))){
649 $output_charset="koi8-x";
651 if (! isset($output_charset)){
652 $output_charset=strtolower($charset);
655 // where is non-braking space symbol
656 switch($output_charset):
669 // don't change string if charset is unmatched
673 // return space instead of non-braking space.
674 return str_replace($nbsp,' ',$string);
678 * Function informs if it is safe to convert given charset to the one that is used by user.
680 * It is safe to use conversion only if user uses utf-8 encoding and when
681 * converted charset is similar to the one that is used by user.
683 * @param string $input_charset Charset of text that needs to be converted
684 * @return bool is it possible to convert to user's charset
686 function is_conversion_safe($input_charset) {
687 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
689 if (isset($lossy_encoding) && $lossy_encoding )
692 // convert to lower case
693 $input_charset = strtolower($input_charset);
695 // Is user's locale Unicode based ?
696 if ( $default_charset == "utf-8" ) {
700 // Charsets that are similar
701 switch ($default_charset) {
703 if ( $input_charset == "iso-8859-5" ||
704 $input_charset == "koi8-r" ||
705 $input_charset == "koi8-u" ) {
711 if ( $input_charset == "iso-8859-13" ||
712 $input_charset == "iso-8859-4" ) {
718 if ( $input_charset == "iso-8859-13" ||
719 $input_charset == "windows-1257" ) {
725 if ( $input_charset == "windows-1251" ||
726 $input_charset == "koi8-r" ||
727 $input_charset == "koi8-u" ) {
733 if ( $input_charset == "iso-8859-4" ||
734 $input_charset == "windows-1257" ) {
740 if ( $input_charset == "windows-1251" ||
741 $input_charset == "iso-8859-5" ||
742 $input_charset == "koi8-u" ) {
748 if ( $input_charset == "windows-1251" ||
749 $input_charset == "iso-8859-5" ||
750 $input_charset == "koi8-r" ) {
761 * Converts html character entities to numeric entities
763 * SquirrelMail encoding functions work only with numeric entities.
764 * This function fixes issues with decoding functions that might convert
765 * some symbols to character entities. Issue is specific to PHP recode
766 * extension decoding. Function is used internally in charset_convert()
768 * @param string $str string that might contain html character entities
769 * @return string string with character entities converted to decimals.
772 function sqi18n_convert_entities($str) {
776 ' ' => ' ',
777 '¡' => '¡',
778 '¢' => '¢',
779 '£' => '£',
780 '¤' => '¤',
782 '¦' => '¦',
783 '§' => '§',
785 '©' => '©',
786 'ª' => 'ª',
787 '«' => '«',
791 '¯' => '¯',
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 'Í' => 'Í',
822 'Î' => 'Î',
823 'Ï' => 'Ï',
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 'í' => 'í',
854 'î' => 'î',
855 'ï' => 'ï',
857 'ñ' => 'ñ',
858 'ò' => 'ò',
859 'ó' => 'ó',
860 'ô' => 'ô',
861 'õ' => 'õ',
862 'ö' => 'ö',
863 '÷' => '÷',
864 'ø' => 'ø',
865 'ù' => 'ù',
866 'ú' => 'ú',
867 'û' => 'û',
868 'ü' => 'ü',
869 'ý' => 'ý',
870 'þ' => 'þ',
871 'ÿ' => 'ÿ',
873 'Œ' => 'Œ',
874 'œ' => 'œ',
875 'Š' => 'Š',
876 'š' => 'š',
877 'Ÿ' => 'Ÿ',
878 // Spacing Modifier Letters
879 'ˆ' => 'ˆ',
880 '˜' => '˜',
881 // General Punctuation
882 ' ' => ' ',
883 ' ' => ' ',
884 ' ' => ' ',
885 '‌' => '‌',
886 '‍' => '‍',
887 '‎' => '‎',
888 '‏' => '‏',
889 '–' => '–',
890 '—' => '—',
891 '‘' => '‘',
892 '’' => '’',
893 '‚' => '‚',
894 '“' => '“',
895 '”' => '”',
896 '„' => '„',
897 '†' => '†',
898 '‡' => '‡',
899 '‰' => '‰',
900 '‹' => '‹',
901 '›' => '›',
902 '€' => '€',
904 'ƒ' => 'ƒ',
906 'Α' => 'Α',
907 'Β' => 'Β',
908 'Γ' => 'Γ',
909 'Δ' => 'Δ',
910 'Ε' => 'Ε',
911 'Ζ' => 'Ζ',
913 'Θ' => 'Θ',
914 'Ι' => 'Ι',
915 'Κ' => 'Κ',
916 'Λ' => 'Λ',
920 'Ο' => 'Ο',
923 'Σ' => 'Σ',
925 'Υ' => 'Υ',
929 'Ω' => 'Ω',
930 'α' => 'α',
931 'β' => 'β',
932 'γ' => 'γ',
933 'δ' => 'δ',
934 'ε' => 'ε',
935 'ζ' => 'ζ',
937 'θ' => 'θ',
938 'ι' => 'ι',
939 'κ' => 'κ',
940 'λ' => 'λ',
944 'ο' => 'ο',
947 'ς' => 'ς',
948 'σ' => 'σ',
950 'υ' => 'υ',
954 'ω' => 'ω',
955 'ϑ' => 'ϑ',
956 'ϒ' => 'ϒ',
958 // General Punctuation
959 '•' => '•',
960 '…' => '…',
961 '′' => '′',
962 '″' => '″',
963 '‾' => '‾',
964 '⁄' => '⁄',
965 // Letterlike Symbols
966 '℘' => '℘',
967 'ℑ' => 'ℑ',
968 'ℜ' => 'ℜ',
969 '™' => '™',
970 'ℵ' => 'ℵ',
972 '←' => '←',
973 '↑' => '↑',
974 '→' => '→',
975 '↓' => '↓',
976 '↔' => '↔',
977 '↵' => '↵',
978 '⇐' => '⇐',
979 '⇑' => '⇑',
980 '⇒' => '⇒',
981 '⇓' => '⇓',
982 '⇔' => '⇔',
983 // Mathematical Operators
984 '∀' => '∀',
985 '∂' => '∂',
986 '∃' => '∃',
987 '∅' => '∅',
988 '∇' => '∇',
989 '∈' => '∈',
990 '∉' => '∉',
992 '∏' => '∏',
993 '∑' => '∑',
994 '−' => '−',
995 '∗' => '∗',
996 '√' => '√',
997 '∝' => '∝',
998 '∞' => '∞',
999 '∠' => '∠',
1000 '∧' => '∧',
1001 '∨' => '∨',
1002 '∩' => '∩',
1003 '∪' => '∪',
1004 '∫' => '∫',
1005 '∴' => '∴',
1006 '∼' => '∼',
1007 '≅' => '≅',
1008 '≈' => '≈',
1009 '≠' => '≠',
1010 '≡' => '≡',
1011 '≤' => '≤',
1012 '≥' => '≥',
1013 '⊂' => '⊂',
1014 '⊃' => '⊃',
1015 '⊄' => '⊄',
1016 '⊆' => '⊆',
1017 '⊇' => '⊇',
1018 '⊕' => '⊕',
1019 '⊗' => '⊗',
1020 '⊥' => '⊥',
1021 '⋅' => '⋅',
1022 // Miscellaneous Technical
1023 '⌈' => '⌈',
1024 '⌉' => '⌉',
1025 '⌊' => '⌊',
1026 '⌋' => '⌋',
1027 '⟨' => '〈',
1028 '⟩' => '〉',
1030 '◊' => '◊',
1031 // Miscellaneous Symbols
1032 '♠' => '♠',
1033 '♣' => '♣',
1034 '♥' => '♥',
1035 '♦' => '♦');
1037 $str = str_replace(array_keys($entities), array_values($entities), $str);
1042 /* ------------------------------ main --------------------------- */
1044 global $squirrelmail_language, $languages, $use_gettext;
1046 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
1047 $squirrelmail_language = '';
1051 * This array specifies the available translations.
1053 * Structure of array:
1054 * $languages['language']['variable'] = 'value'
1056 * Possible 'variable' names:
1057 * NAME - Translation name in English
1058 * CHARSET - Encoding used by translation
1059 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
1060 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
1061 * 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
1062 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
1063 * XTRA_CODE - translation uses special functions. See http://squirrelmail.org/docs/devel/devel-3.html
1065 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
1068 * @global array $languages
1070 $languages['en_US']['NAME'] = 'English';
1071 $languages['en_US']['CHARSET'] = 'iso-8859-1';
1072 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
1073 $languages['en']['ALIAS'] = 'en_US';
1076 * Automatic translation loading from setup.php files.
1077 * Solution for bug. 1240889.
1078 * setup.php file can contain $languages array entries and XTRA_CODE functions.
1080 if (is_dir(SM_PATH
. 'locale') &&
1081 is_readable(SM_PATH
. 'locale')) {
1082 $localedir = dir(SM_PATH
. 'locale');
1083 while($lang_dir=$localedir->read()) {
1084 // remove trailing slash, if present
1085 if (substr($lang_dir,-1)=='/') {
1086 $lang_dir = substr($lang_dir,0,-1);
1088 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
1089 $lang_dir != '.svn' && is_dir(SM_PATH
.'locale/'.$lang_dir) &&
1090 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
1091 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1094 $localedir->close();
1097 /* Detect whether gettext is installed. */
1099 if (function_exists('_')) {
1100 $gettext_flags +
= 1;
1102 if (function_exists('bindtextdomain')) {
1103 $gettext_flags +
= 2;
1105 if (function_exists('textdomain')) {
1106 $gettext_flags +
= 4;
1108 if (function_exists('ngettext')) {
1109 $gettext_flags +
= 8;
1112 /* If gettext is fully loaded, cool */
1113 if ($gettext_flags == 15) {
1114 $use_gettext = true;
1117 /* If ngettext support is missing, load it */
1118 elseif ($gettext_flags == 7) {
1119 $use_gettext = true;
1120 // load internal ngettext functions
1121 include_once(SM_PATH
. 'class/l10n.class.php');
1122 include_once(SM_PATH
. 'functions/ngettext.php');
1125 /* If we can fake gettext, try that */
1126 elseif ($gettext_flags == 0) {
1127 $use_gettext = true;
1128 include_once(SM_PATH
. 'functions/gettext.php');
1130 /* Uh-ho. A weird install */
1131 if (! $gettext_flags & 1) {
1133 * Function is used as replacement in broken installs
1140 if (! $gettext_flags & 2) {
1142 * Function is used as replacement in broken installs
1145 function bindtextdomain() {
1149 if (! $gettext_flags & 4) {
1151 * Function is used as replacemet in broken installs
1154 function textdomain() {
1158 if (! $gettext_flags & 8) {
1160 * Function is used as replacemet in broken installs
1163 function ngettext($str,$str2,$number) {
1171 if (! function_exists('dgettext')) {
1173 * Replacement for broken setups.
1176 function dgettext($domain,$str) {
1180 if (! function_exists('dngettext')) {
1182 * Replacement for broken setups
1185 function dngettext($domain,$str1,$strn,$number) {
1186 return ($number==1 ?
$str1 : $strn);