Add CVS Id tag
[squirrelmail.git] / functions / i18n.php
index 10fe4e8e689d4792ceeb5710272379c3b10eea56..e0375e651d28fcae6edc776ab58b25e53900b2c8 100644 (file)
  * encoded using Unicode entities according to HTML 4.0.
  *
  * $Id$
+ * @package squirrelmail
  */
 
+/** Everything uses global.php... */
 require_once(SM_PATH . 'functions/global.php');
 
-/* Decodes a string to the internal encoding from the given charset */
+/**
+ * Decodes a string to the internal encoding from the given charset
+ * 
+ * @param string $charset
+ * @param string $string Text to be decoded
+ * @return string Decoded text
+ */
 function charset_decode ($charset, $string) {
     global $languages, $squirrelmail_language, $default_charset;
     global $use_php_recode, $use_php_iconv, $agresive_decoding;
@@ -203,7 +211,7 @@ function charset_decode ($charset, $string) {
     } else if ($charset == 'gb2312' and $agresive_decoding ) {
         include_once(SM_PATH . 'functions/decode/gb2312.php');
         $ret = charset_decode_gb2312 ($string);
-    } else if ($charset == 'utf-8') {
+    } else if ($charset == 'utf-8' && $squirrelmail_language != 'ja_JP') {
         include_once(SM_PATH . 'functions/decode/utf-8.php');
        $ret = charset_decode_utf8 ($string);
     } else {
@@ -298,7 +306,11 @@ function set_up_language($sm_language, $do_search = false, $default = false) {
         bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
         textdomain( 'squirrelmail' );
        if (function_exists('bind_textdomain_codeset')) {
-            bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
+            if ($sm_notAlias == 'ja_JP') {
+               bind_textdomain_codeset ("squirrelmail", 'EUC-JP');
+            } else {
+               bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
+           }
        }
        if (isset($languages[$sm_notAlias]['LOCALE'])){
          $longlocale=$languages[$sm_notAlias]['LOCALE'];
@@ -313,10 +325,13 @@ function set_up_language($sm_language, $do_search = false, $default = false) {
         }
        setlocale(LC_ALL, $longlocale);
        $squirrelmail_language = $sm_notAlias;
-        if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
+        if ($squirrelmail_language == 'ja_JP') {
             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 --enable-mbstring).");
+               // Revert to English link has to be added.
+               // stop further execution in order not to get php errors on mb_internal_encoding().
+               return;
             }
             if (function_exists('mb_language')) {
                 mb_language('Japanese');
@@ -771,10 +786,16 @@ function korean_charset_xtra() {
     return $ret;
 }
 
-/* 
+/**
+ * Replaces non-braking spaces inserted by some browsers with regular space
+ * 
  * This function can be used to replace non-braking space symbols 
  * that are inserted in forms by some browsers instead of normal 
  * space symbol.
+ *
+ * @param string $string Text that needs to be cleaned
+ * @param string $charset Charset used in text
+ * @return string Cleaned text
  */
 function cleanup_nbsp($string,$charset) {
 
@@ -814,6 +835,15 @@ endswitch;
  return str_replace($nbsp,' ',$string);
 }
 
+/**
+ * Function informs if it is safe to convert given charset to the one that is used by user.
+ *
+ * It is safe to use conversion only if user uses utf-8 encoding and when 
+ * converted charset is similar to the one that is used by user.
+ *
+ * @param string $input_charset Charset of text that needs to be converted
+ * @return bool is it possible to convert to user's charset
+ */
 function is_conversion_safe($input_charset) {
   global $languages, $sm_notAlias, $default_charset;