Preference that lets the whiners set cursor focus as needed when replying. :)
[squirrelmail.git] / functions / i18n.php
index d2415daf91c87c84b9d767ae9b27ea844f369d5e..8bc708435f82be2c4e5db8020a960b84aea8ae5e 100644 (file)
@@ -19,21 +19,60 @@ require_once(SM_PATH . 'functions/global.php');
 
 /* Decodes a string to the internal encoding from the given charset */
 function charset_decode ($charset, $string) {
-    global $languages, $squirrelmail_language;
+    global $languages, $squirrelmail_language, $default_charset;
 
     if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
         function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
         $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
     }
 
+    $charset = strtolower($charset);
+
+    set_my_charset();
+
+    // Variables that allow to use functions without function_exist() calls
+    $use_php_recode=false;
+    $use_php_iconv=false;
+
+    // Don't do conversion if charset is the same.
+    if ( $charset == strtolower($default_charset) )
+          return htmlspecialchars($string);
+
+    // catch iso-8859-8-i thing
+    if ( $charset == "iso-8859-8-i" )
+              $charset = "iso-8859-8";
+
+    /*
+     * Recode converts html special characters automatically if you use 
+     * 'charset..html' decoding. There is no documented way to put -d option 
+     * into php recode function call.
+     */
+    if ( $use_php_recode ) {
+      if ( $default_charset == "utf-8" ) {
+       // other charsets can be converted to utf-8 without loss.
+       // and output string is smaller
+       $string = recode_string($charset . "..utf-8",$string);
+       return htmlspecialchars($string);
+      } else {
+       $string = recode_string($charset . "..html",$string);
+       // recode does not convert single quote, htmlspecialchars does.
+       $string = str_replace("'", ''', $string);
+       return $string;
+      }
+    }
+
+    // iconv functions does not have html target and can be used only with utf-8
+    if ( $use_php_iconv && $default_charset=='utf-8') {
+      $string = iconv($charset,$default_charset,$string);
+      return htmlspecialchars($string);
+    }
+
+    // If we don't use recode and iconv, we'll do it old way.
+
     /* All HTML special characters are 7 bit and can be replaced first */
     
     $string = htmlspecialchars ($string);
 
-    $charset = strtolower($charset);
-
-    set_my_charset() ;
-
     /* controls cpu and memory intensive decoding cycles */
     $agresive_decoding = false;
 
@@ -121,6 +160,36 @@ function charset_decode ($charset, $string) {
     } else if ($charset == 'windows-1258') {
         include_once(SM_PATH . 'functions/decode/cp1258.php');
         $ret = charset_decode_cp1258 ($string);
+    } else if ($charset == 'x-mac-roman') {
+        include_once(SM_PATH . 'functions/decode/cp10000.php');
+        $ret = charset_decode_cp10000 ($string);
+    } else if ($charset == 'x-mac-greek') {
+        include_once(SM_PATH . 'functions/decode/cp10006.php');
+        $ret = charset_decode_cp10006 ($string);
+    } else if ($charset == 'x-mac-cyrillic') {
+        include_once(SM_PATH . 'functions/decode/cp10007.php');
+        $ret = charset_decode_cp10007 ($string);
+    } else if ($charset == 'x-mac-ukrainian') {
+        include_once(SM_PATH . 'functions/decode/cp10017.php');
+        $ret = charset_decode_cp10017 ($string);
+    } else if ($charset == 'x-mac-centraleurroman') {
+        include_once(SM_PATH . 'functions/decode/cp10029.php');
+        $ret = charset_decode_cp10029 ($string);
+    } else if ($charset == 'x-mac-icelandic') {
+        include_once(SM_PATH . 'functions/decode/cp10079.php');
+        $ret = charset_decode_cp10079 ($string);
+    } else if ($charset == 'x-mac-turkish') {
+        include_once(SM_PATH . 'functions/decode/cp10081.php');
+        $ret = charset_decode_cp10081 ($string);
+    } else if ($charset == 'ibm855') {
+        include_once(SM_PATH . 'functions/decode/cp855.php');
+        $ret = charset_decode_cp855 ($string);
+    } else if ($charset == 'ibm866') {
+        include_once(SM_PATH . 'functions/decode/cp866.php');
+        $ret = charset_decode_cp866 ($string);
+    } else if ($charset == 'tis-620') {
+        include_once(SM_PATH . 'functions/decode/tis620.php');
+        $ret = charset_decode_tis620 ($string);
     } else if ($charset == 'big5' and $agresive_decoding ) {
         include_once(SM_PATH . 'functions/decode/big5.php');
         $ret = charset_decode_big5 ($string);
@@ -202,6 +271,15 @@ function set_up_language($sm_language, $do_search = false, $default = false) {
         $sm_language = $squirrelmail_default_language;
     }
     $sm_notAlias = $sm_language;
+    // Catching removed translation
+    // System reverts to English translation if user prefs contain translation
+    // that is not available in $languages array (admin removed directory
+    // with that translation)
+    if (!isset($languages[$sm_notAlias])) {
+      $sm_notAlias="en_US";
+    }
+
     while (isset($languages[$sm_notAlias]['ALIAS'])) {
         $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
     }
@@ -261,6 +339,10 @@ function set_my_charset(){
     if (!$my_language) {
         $my_language = $squirrelmail_default_language ;
     }
+    // Catch removed translation
+    if (!isset($languages[$my_language])) {
+      $my_language="en_US";
+    }
     while (isset($languages[$my_language]['ALIAS'])) {
         $my_language = $languages[$my_language]['ALIAS'];
     }
@@ -386,6 +468,12 @@ if ( file_exists( SM_PATH . 'locale/nl_NL') ) {
     $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
     $languages['nl']['ALIAS'] = 'nl_NL';
 }
+if ( file_exists( SM_PATH . 'locale/ms_MY') ) {
+    $languages['ms_MY']['NAME']    = 'Bahasa Melayu';
+    $languages['ms_MY']['CHARSET'] = 'iso-8859-1';
+    $languages['my']['ALIAS'] = 'ms_MY';
+}
+
 if ( file_exists( SM_PATH . 'locale/no_NO') ) {
     $languages['no_NO']['NAME']    = 'Norwegian (Bokmål)';
     $languages['no_NO']['CHARSET'] = 'iso-8859-1';
@@ -411,8 +499,8 @@ if ( file_exists( SM_PATH . 'locale/pt_BR') ) {
 }
 if ( file_exists( SM_PATH . 'locale/ru_RU') ) {
     $languages['ru_RU']['NAME']    = 'Russian';
-    $languages['ru_RU']['CHARSET'] = 'koi8-r';
-    $languages['ru_RU']['LOCALE'] = 'ru_RU.KOI8-R';
+    $languages['ru_RU']['CHARSET'] = 'utf-8';
+    $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
     $languages['ru']['ALIAS'] = 'ru_RU';
 }
 if ( file_exists( SM_PATH . 'locale/sr_YU') ) {
@@ -457,8 +545,8 @@ if ( file_exists( SM_PATH . 'locale/th_TH') ) {
 }
 if ( file_exists( SM_PATH . 'locale/lt_LT') ) {
     $languages['lt_LT']['NAME']    = 'Lithuanian';
-    $languages['lt_LT']['CHARSET'] = 'iso-8859-4';
-    $languages['lt_LT']['LOCALE'] = 'lt_LT.ISO-8859-4';
+    $languages['lt_LT']['CHARSET'] = 'utf-8';
+    $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
     $languages['lt']['ALIAS'] = 'lt_LT';
 }
 if ( file_exists( SM_PATH . 'locale/sl_SI') ) {
@@ -739,4 +827,4 @@ endswitch;
 // return space instead of non-braking space. 
  return str_replace($nbsp,' ',$string);
 }
-?>
\ No newline at end of file
+?>