Added redirection from subdirs to prevent file listing.
[squirrelmail.git] / functions / i18n.php
index 20c4e535b0aea2d97d62dc72fd1eb1dda1cc5166..32fb38a961ff3fcf4a47f0ab6033baff9b3450a2 100644 (file)
@@ -58,9 +58,9 @@
       if (ereg("iso-8859-(.*)", $charset, $res)) {
          if ($res[1] == "1")
             return charset_decode_iso_8859_1 ($string);
-         if ($res[1] == "2")
+         else if ($res[1] == "2")
             return charset_decode_iso_8859_2 ($string);
-         if ($res[1] == "7")
+         else if ($res[1] == "7")
             return charset_decode_iso_8859_7 ($string);
          else if ($res[1] == "15")
             return charset_decode_iso_8859_15 ($string);
    function charset_decode_iso_8859_2 ($string) {
       global $default_charset;
 
-      if (strtolower($default_charset) == "iso-8859-7") {
+      if (strtolower($default_charset) == "iso-8859-2") {
          return $string;
       } else {
          // Only do the slow convert if there are 8-bit characters
       }
    }
 
+
+   global $use_gettext;
+   
+   // Detect whether gettext is installed.
+   // If it is, set the flag so we can use it.
+   if (! function_exists("_") || 
+       ! function_exists("bindtextdomain") ||
+       ! function_exists("textdomain"))
+       $use_gettext = false;
+   else
+       $use_gettext = true;
+          
+
+   // Avoid warnings/errors   
+   if (! function_exists("_")) {
+      function _($str) { return $str; };
+   }
+   if (! function_exists("bindtextdomain")) {
+      function bindtextdomain() { return; }
+   }
+   if (! function_exists("textdomain")) {
+      function textdomain() { return; }
+   }
+
+
+   // Set up the language to be output
+   // if $do_search is true, then scan the browser information
+   // for a possible language that we know
+   function set_up_language($sm_language, $do_search = false)
+   {
+      static $SetupAlready = 0;
+      global $HTTP_ACCEPT_LANGUAGE;
+      
+      if ($SetupAlready)
+         return;
+      $SetupAlready = 1;
+     
+      if ($do_search && ! $sm_language && isset($HTTP_ACCEPT_LANGUAGE)) {
+         $sm_language = substr($HTTP_ACCEPT_LANGUAGE, 0, 2);
+      }
+      
+      if (isset($sm_language) && $use_gettext &&
+         $sm_language != "en" && $squirrelmail_language != "" &&
+         $languages[$sm_language]["CHARSET"]) {
+         putenv("LC_ALL=".$sm_language);
+         bindtextdomain("squirrelmail", "../locale/");
+         textdomain("squirrelmail");
+         header ("Content-Type: text/html; charset=".$languages[$sm_language]["CHARSET"]);
+      }
+   }
 ?>