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) {
344 /* Remove minus and characters that might be used in paths from charset
345 * name in order to be able to use it in function names and include calls.
346 * Also make sure it's in lower case (ala "UTF" --> "utf")
348 $charset=preg_replace("/[-:.\/\\\]/",'_', strtolower($charset));
350 // OE ks_c_5601_1987 > cp949
351 $charset=str_replace('ks_c_5601_1987','cp949',$charset);
352 // Moz x-euc-tw > euc-tw
353 $charset=str_replace('x_euc','euc',$charset);
354 // Moz x-windows-949 > cp949
355 $charset=str_replace('x_windows_','cp',$charset);
357 // windows-125x and cp125x charsets
358 $charset=str_replace('windows_','cp',$charset);
361 $charset=str_replace('ibm','cp',$charset);
363 // iso-8859-8-i -> iso-8859-8
364 // use same cycle until I'll find differences
365 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
371 * Set up the language to be output
372 * if $do_search is true, then scan the browser information
373 * for a possible language that we know
375 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
376 * gettext translation bindings and html header information.
378 * Function returns error codes, if there is some fatal error.
380 * 1 = mbstring support is not present,
381 * 2 = mbstring support is not present, user's translation reverted to en_US.
383 * @param string $sm_language Translation used by user's interface
384 * @param bool $do_search Use browser's preferred language detection functions.
386 * @param bool $default Set $sm_language to $squirrelmail_default_language if
387 * language detection fails or language is not set.
389 * @param string $content_type The content type being served currently (OPTIONAL;
390 * if not specified, defaults to whatever the template
391 * set that is in use has defined).
393 * @return int function execution error codes.
396 function set_up_language($sm_language, $do_search=false,
397 $default=false, $content_type='') {
399 static $SetupAlready = 0;
400 global $use_gettext, $languages, $oTemplate,
401 $squirrelmail_language, $squirrelmail_default_language, $default_charset,
402 $sm_notAlias, $username, $data_dir;
408 $SetupAlready = TRUE;
409 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
411 // grab content type if needed
413 if (empty($content_type)) $content_type = $oTemplate->get_content_type();
416 * If function is asked to detect preferred language
417 * OR squirrelmail default language is set to empty string
419 * squirrelmail language ($sm_language) is empty string
420 * (not set in user's prefs and no cookie with language info)
422 * browser provides list of preferred languages
424 * get preferred language from HTTP_ACCEPT_LANGUAGE header
426 if (($do_search ||
empty($squirrelmail_default_language)) &&
428 isset($accept_lang)) {
429 // TODO: use more than one language, if first language is not available
430 // FIXME: function assumes that string contains two or more characters.
431 // FIXME: some languages use 5 chars
432 $sm_language = substr($accept_lang, 0, 2);
436 * If language preference is not set OR script asks to use default language
438 * default squirrelmail language is not set to empty string
440 * use default squirrelmail language value from configuration.
442 if ((!$sm_language||
$default) &&
443 ! empty($squirrelmail_default_language)) {
444 $squirrelmail_language = $squirrelmail_default_language;
445 $sm_language = $squirrelmail_default_language;
448 /** provide failsafe language when detection fails */
449 if (! $sm_language) $sm_language='en_US';
451 $sm_notAlias = $sm_language;
453 // Catching removed translation
454 // System reverts to English translation if user prefs contain translation
455 // that is not available in $languages array
456 if (!isset($languages[$sm_notAlias])) {
457 $sm_notAlias="en_US";
460 while (isset($languages[$sm_notAlias]['ALIAS'])) {
461 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
464 if ( isset($sm_language) &&
466 $sm_language != '' &&
467 isset($languages[$sm_notAlias]['CHARSET']) ) {
468 sq_bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
469 sq_textdomain( 'squirrelmail' );
471 // Use LOCALE key, if it is set.
472 if (isset($languages[$sm_notAlias]['LOCALE'])){
473 $longlocale=$languages[$sm_notAlias]['LOCALE'];
475 $longlocale=$sm_notAlias;
478 // try setting locale
479 $retlocale=sq_setlocale(LC_ALL
, $longlocale);
481 // check if locale is set and assign that locale to $longlocale
482 // in order to use it in putenv calls.
483 if (! is_bool($retlocale)) {
484 $longlocale=$retlocale;
485 } elseif (is_array($longlocale)) {
486 // setting of all locales failed.
487 // we need string instead of array used in LOCALE key.
488 $longlocale=$sm_notAlias;
491 if ( !((bool)ini_get('safe_mode')) &&
492 getenv( 'LC_ALL' ) != $longlocale ) {
493 putenv( "LC_ALL=$longlocale" );
494 putenv( "LANG=$longlocale" );
495 putenv( "LANGUAGE=$longlocale" );
496 putenv( "LC_NUMERIC=C" );
497 if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" );
499 // Workaround for plugins that use numbers with floating point
500 // It might be removed if plugins use correct decimal delimiters
501 // according to locale settings.
502 setlocale(LC_NUMERIC
, 'C');
503 // Workaround for specific Turkish strtolower/strtoupper rules.
504 // Many functions expect English conversion rules.
505 if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE
,'C');
508 * Set text direction/alignment variables
509 * When language environment is setup, scripts can use these globals
510 * without accessing $languages directly and making checks for optional
513 global $text_direction, $left_align, $right_align;
514 if (isset($languages[$sm_notAlias]['DIR']) &&
515 $languages[$sm_notAlias]['DIR'] == 'rtl') {
518 * @global string $text_direction
520 $text_direction='rtl';
523 * @global string $left_align
528 * @global string $right_align
532 $text_direction='ltr';
534 $right_align='right';
537 $squirrelmail_language = $sm_notAlias;
538 if ($squirrelmail_language == 'ja_JP') {
539 $oTemplate->header ('Content-Type: ' . $content_type . '; charset=EUC-JP');
540 if (!function_exists('mb_internal_encoding')) {
541 // Error messages can't be displayed here
543 // Revert to English if possible.
544 if (function_exists('setPref') && $username!='' && $data_dir!="") {
545 setPref($data_dir, $username, 'language', "en_US");
548 // stop further execution in order not to get php errors on mb_internal_encoding().
551 if (function_exists('mb_language')) {
552 mb_language('Japanese');
554 mb_internal_encoding('EUC-JP');
555 mb_http_output('pass');
556 } elseif ($squirrelmail_language == 'en_US') {
557 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $default_charset );
559 $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $languages[$sm_notAlias]['CHARSET'] );
562 * mbstring.func_overload fix (#929644).
564 * php mbstring extension can replace standard string functions with their multibyte
565 * equivalents. See http://www.php.net/ref.mbstring#mbstring.overload. This feature
566 * was added in php v.4.2.0
568 * Some SquirrelMail functions work with 8bit strings in bytes. If interface is forced
569 * to use mbstring functions and mbstring internal encoding is set to multibyte charset,
570 * interface can't trust regular string functions. Due to mbstring overloading design
571 * limits php scripts can't control this setting.
573 * This hack should fix some issues related to 8bit strings in passwords. Correct fix is
574 * to disable mbstring overloading. Japanese translation uses different internal encoding.
576 if ($squirrelmail_language != 'ja_JP' &&
577 function_exists('mb_internal_encoding') &&
578 check_php_version(4,2,0) &&
579 (int)ini_get('mbstring.func_overload')!=0) {
580 mb_internal_encoding('pass');
587 * Sets default_charset variable according to the one that is used by user's translations.
589 * Function changes global $default_charset variable in order to be sure, that it
590 * contains charset used by user's translation. Sanity of $squirrelmail_language
591 * and $default_charset combination is also tested.
593 * There can be a $default_charset setting in the
594 * config.php file, but the user may have a different language
595 * selected for a user interface. This function checks the
596 * language selected by the user and tags the outgoing messages
597 * with the appropriate charset corresponding to the language
598 * selection. This is "more right" (tm), than just stamping the
599 * message blindly with the system-wide $default_charset.
601 function set_my_charset(){
602 global $data_dir, $username, $default_charset, $languages, $squirrelmail_language;
604 $my_language = getPref($data_dir, $username, 'language');
606 $my_language = $squirrelmail_language ;
608 // Catch removed translation
609 if (!isset($languages[$my_language])) {
610 $my_language="en_US";
612 while (isset($languages[$my_language]['ALIAS'])) {
613 $my_language = $languages[$my_language]['ALIAS'];
615 $my_charset = $languages[$my_language]['CHARSET'];
616 if ($my_language!='en_US') {
617 $default_charset = $my_charset;
622 * Replaces non-braking spaces inserted by some browsers with regular space
624 * This function can be used to replace non-braking space symbols
625 * that are inserted in forms by some browsers instead of normal
628 * @param string $string Text that needs to be cleaned
629 * @param string $charset Charset used in text
630 * @return string Cleaned text
632 function cleanup_nbsp($string,$charset) {
634 // reduce number of case statements
635 if (stristr('iso-8859-',substr($charset,0,9))){
636 $output_charset="iso-8859-x";
638 if (stristr('windows-125',substr($charset,0,11))){
639 $output_charset="cp125x";
641 if (stristr('koi8',substr($charset,0,4))){
642 $output_charset="koi8-x";
644 if (! isset($output_charset)){
645 $output_charset=strtolower($charset);
648 // where is non-braking space symbol
649 switch($output_charset):
662 // don't change string if charset is unmatched
666 // return space instead of non-braking space.
667 return str_replace($nbsp,' ',$string);
671 * Function informs if it is safe to convert given charset to the one that is used by user.
673 * It is safe to use conversion only if user uses utf-8 encoding and when
674 * converted charset is similar to the one that is used by user.
676 * @param string $input_charset Charset of text that needs to be converted
677 * @return bool is it possible to convert to user's charset
679 function is_conversion_safe($input_charset) {
680 global $languages, $sm_notAlias, $default_charset, $lossy_encoding;
682 if (isset($lossy_encoding) && $lossy_encoding )
685 // convert to lower case
686 $input_charset = strtolower($input_charset);
688 // Is user's locale Unicode based ?
689 if ( $default_charset == "utf-8" ) {
693 // Charsets that are similar
694 switch ($default_charset) {
696 if ( $input_charset == "iso-8859-5" ||
697 $input_charset == "koi8-r" ||
698 $input_charset == "koi8-u" ) {
704 if ( $input_charset == "iso-8859-13" ||
705 $input_charset == "iso-8859-4" ) {
711 if ( $input_charset == "iso-8859-13" ||
712 $input_charset == "windows-1257" ) {
718 if ( $input_charset == "windows-1251" ||
719 $input_charset == "koi8-r" ||
720 $input_charset == "koi8-u" ) {
726 if ( $input_charset == "iso-8859-4" ||
727 $input_charset == "windows-1257" ) {
733 if ( $input_charset == "windows-1251" ||
734 $input_charset == "iso-8859-5" ||
735 $input_charset == "koi8-u" ) {
741 if ( $input_charset == "windows-1251" ||
742 $input_charset == "iso-8859-5" ||
743 $input_charset == "koi8-r" ) {
754 * Converts html character entities to numeric entities
756 * SquirrelMail encoding functions work only with numeric entities.
757 * This function fixes issues with decoding functions that might convert
758 * some symbols to character entities. Issue is specific to PHP recode
759 * extension decoding. Function is used internally in charset_convert()
761 * @param string $str string that might contain html character entities
762 * @return string string with character entities converted to decimals.
765 function sqi18n_convert_entities($str) {
769 ' ' => ' ',
770 '¡' => '¡',
771 '¢' => '¢',
772 '£' => '£',
773 '¤' => '¤',
775 '¦' => '¦',
776 '§' => '§',
778 '©' => '©',
779 'ª' => 'ª',
780 '«' => '«',
784 '¯' => '¯',
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 'Í' => 'Í',
815 'Î' => 'Î',
816 'Ï' => 'Ï',
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 'í' => 'í',
847 'î' => 'î',
848 'ï' => 'ï',
850 'ñ' => 'ñ',
851 'ò' => 'ò',
852 'ó' => 'ó',
853 'ô' => 'ô',
854 'õ' => 'õ',
855 'ö' => 'ö',
856 '÷' => '÷',
857 'ø' => 'ø',
858 'ù' => 'ù',
859 'ú' => 'ú',
860 'û' => 'û',
861 'ü' => 'ü',
862 'ý' => 'ý',
863 'þ' => 'þ',
864 'ÿ' => 'ÿ',
866 'Œ' => 'Œ',
867 'œ' => 'œ',
868 'Š' => 'Š',
869 'š' => 'š',
870 'Ÿ' => 'Ÿ',
871 // Spacing Modifier Letters
872 'ˆ' => 'ˆ',
873 '˜' => '˜',
874 // General Punctuation
875 ' ' => ' ',
876 ' ' => ' ',
877 ' ' => ' ',
878 '‌' => '‌',
879 '‍' => '‍',
880 '‎' => '‎',
881 '‏' => '‏',
882 '–' => '–',
883 '—' => '—',
884 '‘' => '‘',
885 '’' => '’',
886 '‚' => '‚',
887 '“' => '“',
888 '”' => '”',
889 '„' => '„',
890 '†' => '†',
891 '‡' => '‡',
892 '‰' => '‰',
893 '‹' => '‹',
894 '›' => '›',
895 '€' => '€',
897 'ƒ' => 'ƒ',
899 'Α' => 'Α',
900 'Β' => 'Β',
901 'Γ' => 'Γ',
902 'Δ' => 'Δ',
903 'Ε' => 'Ε',
904 'Ζ' => 'Ζ',
906 'Θ' => 'Θ',
907 'Ι' => 'Ι',
908 'Κ' => 'Κ',
909 'Λ' => 'Λ',
913 'Ο' => 'Ο',
916 'Σ' => 'Σ',
918 'Υ' => 'Υ',
922 'Ω' => 'Ω',
923 'α' => 'α',
924 'β' => 'β',
925 'γ' => 'γ',
926 'δ' => 'δ',
927 'ε' => 'ε',
928 'ζ' => 'ζ',
930 'θ' => 'θ',
931 'ι' => 'ι',
932 'κ' => 'κ',
933 'λ' => 'λ',
937 'ο' => 'ο',
940 'ς' => 'ς',
941 'σ' => 'σ',
943 'υ' => 'υ',
947 'ω' => 'ω',
948 'ϑ' => 'ϑ',
949 'ϒ' => 'ϒ',
951 // General Punctuation
952 '•' => '•',
953 '…' => '…',
954 '′' => '′',
955 '″' => '″',
956 '‾' => '‾',
957 '⁄' => '⁄',
958 // Letterlike Symbols
959 '℘' => '℘',
960 'ℑ' => 'ℑ',
961 'ℜ' => 'ℜ',
962 '™' => '™',
963 'ℵ' => 'ℵ',
965 '←' => '←',
966 '↑' => '↑',
967 '→' => '→',
968 '↓' => '↓',
969 '↔' => '↔',
970 '↵' => '↵',
971 '⇐' => '⇐',
972 '⇑' => '⇑',
973 '⇒' => '⇒',
974 '⇓' => '⇓',
975 '⇔' => '⇔',
976 // Mathematical Operators
977 '∀' => '∀',
978 '∂' => '∂',
979 '∃' => '∃',
980 '∅' => '∅',
981 '∇' => '∇',
982 '∈' => '∈',
983 '∉' => '∉',
985 '∏' => '∏',
986 '∑' => '∑',
987 '−' => '−',
988 '∗' => '∗',
989 '√' => '√',
990 '∝' => '∝',
991 '∞' => '∞',
992 '∠' => '∠',
993 '∧' => '∧',
995 '∩' => '∩',
996 '∪' => '∪',
997 '∫' => '∫',
998 '∴' => '∴',
999 '∼' => '∼',
1000 '≅' => '≅',
1001 '≈' => '≈',
1002 '≠' => '≠',
1003 '≡' => '≡',
1004 '≤' => '≤',
1005 '≥' => '≥',
1006 '⊂' => '⊂',
1007 '⊃' => '⊃',
1008 '⊄' => '⊄',
1009 '⊆' => '⊆',
1010 '⊇' => '⊇',
1011 '⊕' => '⊕',
1012 '⊗' => '⊗',
1013 '⊥' => '⊥',
1014 '⋅' => '⋅',
1015 // Miscellaneous Technical
1016 '⌈' => '⌈',
1017 '⌉' => '⌉',
1018 '⌊' => '⌊',
1019 '⌋' => '⌋',
1020 '⟨' => '〈',
1021 '⟩' => '〉',
1023 '◊' => '◊',
1024 // Miscellaneous Symbols
1025 '♠' => '♠',
1026 '♣' => '♣',
1027 '♥' => '♥',
1028 '♦' => '♦');
1030 $str = str_replace(array_keys($entities), array_values($entities), $str);
1035 /* ------------------------------ main --------------------------- */
1037 global $squirrelmail_language, $languages, $use_gettext;
1039 if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE
)) {
1040 $squirrelmail_language = '';
1044 * Array specifies the available translations.
1046 * Structure of array:
1047 * $languages['language']['variable'] = 'value'
1049 * Possible 'variable' names:
1050 * NAME - Translation name in English
1051 * CHARSET - Encoding used by translation
1052 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
1053 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
1054 * 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
1055 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
1056 * XTRA_CODE - translation uses special functions. See doc/i18n.txt
1058 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
1061 * @global array $languages
1063 $languages['en_US']['NAME'] = 'English';
1064 $languages['en_US']['CHARSET'] = 'iso-8859-1';
1065 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
1066 $languages['en']['ALIAS'] = 'en_US';
1069 * Automatic translation loading from setup.php files.
1070 * Solution for bug. 1240889.
1071 * setup.php file can contain $languages array entries and XTRA_CODE functions.
1073 if (is_dir(SM_PATH
. 'locale') &&
1074 is_readable(SM_PATH
. 'locale')) {
1075 $localedir = dir(SM_PATH
. 'locale');
1076 while($lang_dir=$localedir->read()) {
1077 // remove trailing slash, if present
1078 if (substr($lang_dir,-1)=='/') {
1079 $lang_dir = substr($lang_dir,0,-1);
1081 if ($lang_dir != '..' && $lang_dir != '.' && $lang_dir != 'CVS' &&
1082 $lang_dir != '.svn' && is_dir(SM_PATH
.'locale/'.$lang_dir) &&
1083 file_exists(SM_PATH
.'locale/'.$lang_dir.'/setup.php')) {
1084 include_once(SM_PATH
.'locale/'.$lang_dir.'/setup.php');
1087 $localedir->close();
1090 /* Detect whether gettext is installed. */
1092 if (function_exists('_')) {
1093 $gettext_flags +
= 1;
1095 if (function_exists('bindtextdomain')) {
1096 $gettext_flags +
= 2;
1098 if (function_exists('textdomain')) {
1099 $gettext_flags +
= 4;
1101 if (function_exists('ngettext')) {
1102 $gettext_flags +
= 8;
1105 /* If gettext is fully loaded, cool */
1106 if ($gettext_flags == 15) {
1107 $use_gettext = true;
1110 /* If ngettext support is missing, load it */
1111 elseif ($gettext_flags == 7) {
1112 $use_gettext = true;
1113 // load internal ngettext functions
1114 include_once(SM_PATH
. 'class/l10n.class.php');
1115 include_once(SM_PATH
. 'functions/ngettext.php');
1118 /* If we can fake gettext, try that */
1119 elseif ($gettext_flags == 0) {
1120 $use_gettext = true;
1121 include_once(SM_PATH
. 'functions/gettext.php');
1123 /* Uh-ho. A weird install */
1124 if (! $gettext_flags & 1) {
1126 * Function is used as replacement in broken installs
1133 if (! $gettext_flags & 2) {
1135 * Function is used as replacement in broken installs
1138 function bindtextdomain() {
1142 if (! $gettext_flags & 4) {
1144 * Function is used as replacemet in broken installs
1147 function textdomain() {
1151 if (! $gettext_flags & 8) {
1153 * Function is used as replacemet in broken installs
1156 function ngettext($str,$str2,$number) {
1164 if (! function_exists('dgettext')) {
1166 * Replacement for broken setups.
1169 function dgettext($domain,$str) {
1173 if (! function_exists('dngettext')) {
1175 * Replacement for broken setups
1178 function dngettext($domain,$str1,$strn,$number) {
1179 return ($number==1 ?
$str1 : $strn);