Paul's changes
[squirrelmail.git] / functions / i18n.php
index 1cbb8d05c5c432b587f2e06f52ebaebc3322d06a..f7ad4658d76398f62a3e47766275cefbc4c8baec 100644 (file)
 
 /* Decodes a string to the internal encoding from the given charset */
 function charset_decode ($charset, $string) {
+    global $languages, $squirrelmail_language;
+
+    if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
+        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
+        $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
+    }
 
     /* All HTML special characters are 7 bit and can be replaced first */
     $string = htmlspecialchars ($string);
@@ -673,6 +679,63 @@ function charset_decode_koi8r ($string) {
     return $string;
 }
 
+
+/*
+ * Japanese charset extra function
+ *
+ */
+function japanese_charset_xtra() {
+    $ret = func_get_arg(1);  /* default return value */
+    if (function_exists('mb_detect_encoding')) {
+        switch (func_get_arg(0)) { /* action */
+        case 'decode':
+            $detect_encoding = mb_detect_encoding($ret);
+            if ($detect_encoding == 'JIS' ||
+                $detect_encoding == 'EUC-JP' ||
+                $detect_encoding == 'SJIS') {
+                
+                $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
+            }
+            break;
+        case 'encode':
+            $detect_encoding = mb_detect_encoding($ret);
+            if ($detect_encoding == 'JIS' ||
+                $detect_encoding == 'EUC-JP' ||
+                $detect_encoding == 'SJIS') {
+                
+                $ret = mb_convert_encoding($ret, 'JIS', 'AUTO');
+            }
+            break;
+        case 'strimwidth':
+            $width = func_get_arg(2);
+            $ret = mb_strimwidth($ret, 0, $width, '...'); 
+            break;
+        case 'encodeheader':
+            $ret = mb_encode_mimeheader($ret);
+            break;
+        case 'decodeheader':
+            $ret = str_replace("\t", "", $ret);
+            if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
+                $ret = mb_decode_mimeheader($ret);
+            $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
+            break;
+        case 'downloadfilename':
+            $useragent = func_get_arg(2);
+            if (strstr($useragent, 'Windows') !== false ||
+                strstr($useragent, 'Mac_') !== false) {
+                $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
+            } else {
+                $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
+}
+            break;
+        default:
+            break;
+        }
+    }
+    return $ret;
+}
+
+
 /*
  * Set up the language to be output
  * if $do_search is true, then scan the browser information
@@ -717,9 +780,18 @@ function set_up_language($sm_language, $do_search = false) {
         }
         setlocale(LC_ALL, $sm_notAlias);
         $squirrelmail_language = $sm_notAlias;
+        if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
+            header ('Content-Type: text/html; charset=EUC-JP');
+            if (!function_exists('mb_internal_encoding')) {
+                echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --with-mbstring).");
+            }
+            mb_internal_encoding('EUC-JP');
+            mb_http_output('pass');
+        } else {
         header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
     }
 }
+}
 
 function set_my_charset(){
 
@@ -820,6 +892,11 @@ $languages['it_IT']['NAME']    = 'Italian';
 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
 $languages['it']['ALIAS'] = 'it_IT';
 
+$languages['ja_JP']['NAME']    = 'Japanese';
+$languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
+$languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
+$languages['ja']['ALIAS'] = 'ja_JP';
+
 $languages['ko_KR']['NAME']    = 'Korean';
 $languages['ko_KR']['CHARSET'] = 'euc-KR';
 $languages['ko']['ALIAS'] = 'ko_KR';
@@ -860,12 +937,14 @@ $languages['tr_TR']['NAME']    = 'Turkish';
 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
 $languages['tr']['ALIAS'] = 'tr_TR';
 
-// it's zh_TW, actually.
-
 $languages['zh_TW']['NAME']    = 'Taiwan';
 $languages['zh_TW']['CHARSET'] = 'big5';
 $languages['tw']['ALIAS'] = 'zh_TW';
 
+$languages['zh_TW']['NAME']    = 'Chinese';
+$languages['zh_TW']['CHARSET'] = 'gb2312';
+$languages['tw']['ALIAS'] = 'zh_CN';
+
 $languages['sk_SK']['NAME']     = 'Slovak';
 $languages['sk_SK']['CHARSET']  = 'iso-8859-2';
 $languages['sk']['ALIAS']       = 'sk_SK';
@@ -890,6 +969,14 @@ $languages['bg_BG']['NAME']    = 'Bulgarian';
 $languages['bg_BG']['CHARSET'] = 'windows-1251';
 $languages['bg']['ALIAS'] = 'bg_BG';
 
+// Right to left languages
+
+$languages['he_HE']['NAME']    = 'Hebrew';
+$languages['he_HE']['CHARSET'] = 'windows-1255';
+$languages['he_HE']['DIR']     = 'rtl';
+$languages['he']['ALIAS']      = 'he_HE';
+
+
 /* Detect whether gettext is installed. */
 $gettext_flags = 0;
 if (function_exists('_')) {