LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2898|回复: 15

OpenExchangeServer中文化问题解决方案

[复制链接]
发表于 2003-4-1 13:31:44 | 显示全部楼层 |阅读模式
经过二周多对openExchangeserver代码的研究,基本解决了中文无法的问题,用i18n中的ResourceBundle代替了原来的多语言结构,把全部的环节用UTF8编码,基本解决了中文问题。
现在存在的问题:
1、语言包没有来得及汉化,也就同messages.nlg中的信息要翻译成中文,用native2ascii转成unicode
2、只做了webmail部份,其它部份应该也就可以,不就实在没时间看了
3、因为全部用unicode所以在web方式下没任何问题,也不用改web页面,从outlook等发邮件没问题,不过从web发的邮件在outlook下看,要把编码设为utf-8才能看
4、没有对中文再没一种语言,直接用EN来做的,不过也不复杂,有时间再做
4、其它没有发现的问题

如果谁有时间可以把messages.nlg中的信息全部?翻译一下,然后合在一起做个中文版发出来大家一起试用。
发表于 2003-4-1 14:04:18 | 显示全部楼层
首先,请兄弟原谅我修改了你的标题,因为我想把它顶置,作为一个方案,提供给大家。
好,好文章,希望兄弟再接再厉,这算是一个小项目吧。做好了,我们可以超过Redhat了。如果问题解决了,这个东西也就有使用价值了。虽然不能得到升级,但是,实际应用中把它放在防火墙后面,也应该会安全的。
有什么解决的问题,希望兄弟继续跟帖,兄弟可以编辑自己的帖子,不断完善它(点击你帖子右下角的第一个图标)。其他兄弟们也可以尝试,踊跃发言!
 楼主| 发表于 2003-4-1 16:09:00 | 显示全部楼层
发表于 2003-4-1 18:36:34 | 显示全部楼层
请兄弟把过程相信写出来如何?毕竟不是每个兄弟都能容易的接受。在这方面,你现在是权威啊。哈哈。所以希望兄弟能把你顶上那个帖子再详细化一点。
 楼主| 发表于 2003-4-7 09:32:39 | 显示全部楼层
1.webmail servlet的改动,将以下代码编译后覆盖原来的/srv/www/servlet下的webmail.class
就是反把fAr子函数变为以下代码:
private String[] fAr(String s, String s1)
    {
        String as[] = new String[2];
        try
        {
            if(s != null)
            {
                as[0] = new String(s.getBytes(),System.getProperty("file.encoding"));
            }
            if(s1 != null)
            {
                as[1] = new String(s1.getBytes(),System.getProperty("file.encoding"));            }
        }
        catch(Exception exception)
        {
            as[0] = s;
            as[1] = s1;
        }
        return as;
    }
 楼主| 发表于 2003-4-7 09:34:43 | 显示全部楼层
2、把nas包下的Configuration 变为以下代码:
package nas;

import java.io.*;
import java.util.StringTokenizer;
import java.util.Vector;
import netline.nastools.nasUtilities;

public class Configuration
{

    nasUtilities nu;
    private String htmlPath;
    private String stylePath;
    private String imagePath;
    private String javascriptPath;
    private String dataPath;
    private String npSqlPath;
    private String npSqlDriver;
    private String npSqlUser;
    private String npSqlPass;
    private String baseDC;
    private String host;
    private int quotaWarn;
    private String default_encoding;
    private boolean can_select_encoding;
    private Vector available_encodings;

    public Configuration()
    {
        nu = new nasUtilities();
        htmlPath = null;
        stylePath = null;
        imagePath = null;
        javascriptPath = null;
        dataPath = null;
        npSqlPath = null;
        npSqlDriver = null;
        npSqlUser = null;
        npSqlPass = null;
        baseDC = null;
        host = null;
        quotaWarn = -1;
        default_encoding = "UTF-8";
        can_select_encoding = false;
        available_encodings = new Vector();
    }

    public void getSystemConfiguration()
        throws Exception
    {
        File file = new File(System.getProperty("user.dir") + "/config/system.cfg");
        if(!file.exists())
        {
            System.out.println("!ERR! " + nu.getDateAndTime() + " LOAD CONF -> COULDN'T FIND FILE --> system.cfg !!NOTHING WILL WORK!!");
        }
        FileReader filereader = new FileReader(file);
        BufferedReader bufferedreader = new BufferedReader(filereader);
        for(String s = ""; (s = bufferedreader.readLine()) != null;)
        {
            if(s.startsWith("HTML-SPO="))
            {
                htmlPath = seperateValue(s);
            } else
            if(s.startsWith("IMAGE-LINK="))
            {
                imagePath = seperateValue(s);
            } else
            if(s.startsWith("STYLESHEET-LINK="))
            {
                stylePath = seperateValue(s);
            } else
            if(s.startsWith("JAVASCRIPT-LINK="))
            {
                javascriptPath = seperateValue(s);
            } else
            if(s.startsWith("DATA-SRC="))
            {
                dataPath = seperateValue(s);
                if(!(new File(dataPath)).isDirectory())
                {
                    (new File(dataPath)).mkdir();
                }
            } else
            if(s.startsWith("NP-PSQL-PATH="))
            {
                npSqlPath = seperateValue(s);
            } else
            if(s.startsWith("NP-SQL-DRIVER="))
            {
                npSqlDriver = seperateValue(s);
            } else
            if(s.startsWith("NP-PSQL-USER="))
            {
                npSqlUser = seperateValue(s);
            } else
            if(s.startsWith("NP-PSQL-PASS="))
            {
                npSqlPass = seperateValue(s);
            } else
            if(s.startsWith("DEFAULT-ENCODING"))
            {
                String s3 = seperateValue(s);
                if(s3.toUpperCase().indexOf("AUTO") != -1)
                {
                    default_encoding = System.getProperty("file.encoding");
                } else
                {
                    try
                    {
                        String s7 = new String("test".getBytes(), s3);
                        default_encoding = s3;
                    }
                    catch(UnsupportedEncodingException unsupportedencodingexception)
                    {
                        System.out.println("!ERR!  No valid default encoding: " + s3 + ", use system default: " + System.getProperty("file.encoding"));
                    }
                }
            } else
            if(s.startsWith("USER-CAN-SELECT-ENCODING"))
            {
                String s4 = seperateValue(s);
                if(s4.trim().toUpperCase().equals("TRUE"))
                {
                    can_select_encoding = true;
                } else
                {
                    can_select_encoding = false;
                }
            } else
            if(s.startsWith("AVAILABLE-ENCODINGS") && can_select_encoding)
            {
                String s5 = seperateValue(s);
                StringTokenizer stringtokenizer = new StringTokenizer(s5, ",");
                boolean flag = false;
                if(stringtokenizer.countTokens() >= 1)
                {
                    while(stringtokenizer.hasMoreTokens())
                    {
                        String s8 = stringtokenizer.nextToken();
                        try
                        {
                            String s9 = new String("test".getBytes(), s8);
                            if(s8.equals(default_encoding))
                            {
                                available_encodings.insertElementAt(s8, 0);
                                flag = true;
                            } else
                            {
                                available_encodings.add(s8);
                            }
                        }
                        catch(UnsupportedEncodingException unsupportedencodingexception1)
                        {
                            System.out.println("!ERR!  Ignore no valid encoding: " + s8);
                        }
                    }
                }
                if(!flag)
                {
                    available_encodings.insertElementAt(default_encoding, 0);
                }
            }
        }

        try
        {
            File file1 = new File("/etc/openldap/ldap.conf");
            if(!file1.exists())
            {
                System.out.println("!ERR! " + nu.getDateAndTime() + " LOAD CONF -> COULDN'T FIND FILE --> /etc/openldap/ldap.conf !!LDAP-FUNCTIONS WI" +
"LL NOT WORK!!"
);
            } else
            {
                filereader = new FileReader(file1);
                bufferedreader = new BufferedReader(filereader);
                for(String s1 = ""; (s1 = bufferedreader.readLine()) != null;)
                {
                    if(s1.toUpperCase().startsWith("BASE"))
                    {
                        baseDC = s1.substring(5, s1.length()).trim();
                    } else
                    if(s1.toUpperCase().startsWith("HOST"))
                    {
                        host = s1.substring(5, s1.length()).trim();
                    }
                }

            }
        }
        catch(Exception exception)
        {
            System.out.println("!ERR! Configuration / getSystemConfiguration -> COULDN'T GET BASE-DC --> " + exception.getMessage());
        }
        try
        {
            File file2 = new File("/etc/imapd.conf");
            if(file2.exists())
            {
                filereader = new FileReader(file2);
                bufferedreader = new BufferedReader(filereader);
                for(String s2 = ""; (s2 = bufferedreader.readLine()) != null;)
                {
                    if(s2.toUpperCase().startsWith("QUOTAWARN:"))
                    {
                        String s6 = s2.substring(11, s2.length()).trim();
                        try
                        {
                            quotaWarn = (new Integer(s6)).intValue();
                        }
                        catch(NumberFormatException numberformatexception) { }
                    }
                }

            }
        }
        catch(Exception exception1)
        {
            System.out.println("!ERR! Configuration / getSystemConfiguration -> COULDN'T GET QUOTA-WARN --> " + exception1.getMessage());
        }
        bufferedreader.close();
        filereader.close();
    }

    public String getBaseDC()
    {
        return baseDC;
    }

    public String getHost()
    {
        return host;
    }

    public int getQuotaWarn()
    {
        return quotaWarn;
    }

    public String getHtmlSpo()
    {
        return htmlPath;
    }

    public String getStyleLink()
    {
        return stylePath;
    }

    public String getImageLink()
    {
        return imagePath;
    }

    public String getJavascriptLink()
    {
        return javascriptPath;
    }

    public String getDataSrc()
    {
        return dataPath;
    }

    private String seperateValue(String s)
    {
        try
        {
            if(s.indexOf("=") != -1)
            {
                return s.substring(s.indexOf("\"") + 1, s.lastIndexOf("\""));
            } else
            {
                return null;
            }
        }
        catch(Exception exception)
        {
            System.out.println("!ERR! Configuration/readConfiguration -> err parsing line --> " + s);
        }
        return null;
    }

    public String getNpSqlPath()
    {
        return npSqlPath;
    }

    public String getNpSqlDriver()
    {
        return npSqlDriver;
    }

    public String getNpSqlUser()
    {
        return npSqlUser;
    }

    public String getNpSqlPass()
    {
        return npSqlPass;
    }

    public String getDefaultEncoding()
    {
        return default_encoding;
    }

    public boolean userCanSelectEncoding()
    {
        return can_select_encoding;
    }

    public Vector getAvailableEncodings()
    {
        return available_encodings;
    }
}
 楼主| 发表于 2003-4-7 09:36:15 | 显示全部楼层
3、把nas包中的LanguageManagement 变为如下代码:
package nas;

import java.io.*;
import java.util.*;
import java.util.Enumeration;
import java.util.Hashtable;
import netline.nastools.nasUtilities;

public class LanguageManagement extends Hashtable
{

    nasUtilities nu;
    private String configFile;
    private String messageFile;
    private String language;
    private Hashtable languages;

    public LanguageManagement()
    {
        nu = new nasUtilities();
        configFile = "lang.cfg";
        messageFile = "messages.nlg";
        language = "DE";
        languages = new Hashtable();
    }

    public void setLanguage(String s)
    {
        language = s;
    }

    public void readConfiguration()
        throws Exception
    {
        if((new File(System.getProperty("user.dir") + "/config/" + configFile)).exists())
        {
            FileReader filereader = new FileReader(System.getProperty("user.dir") + "/config/" + configFile);
            BufferedReader bufferedreader = new BufferedReader(filereader);
            for(String s = ""; (s = bufferedreader.readLine()) != null;)
            {
                s = s.trim();
                if(!s.startsWith("#") && s.trim().length() != 0 && s.indexOf("=") != -1)
                {
                    String s2 = s.substring(0, s.indexOf("="));
                    String s4 = s.substring(s.indexOf("=") + 1, s.length());
                    languages.put(s2, s4);
                }
            }

            filereader.close();
        } else
        {
            System.out.println("!ERR! " + nu.getDateAndTime() + " LanguageManagement/readConfiguration -> COULDN'T FIND FILE ---> lang.cfg");
        }
        if((new File(System.getProperty("user.dir") + "/config/" + messageFile)).exists())
        {
          FileInputStream in = new FileInputStream(System.getProperty("user.dir") + "/config/" + messageFile);
          PropertyResourceBundle cr = new PropertyResourceBundle(in);
          Enumeration em = cr.getKeys();
          while(em.hasMoreElements()){
            String s3 = (String)em.nextElement();
            String s5 = cr.getString(s3);
            put(s3,s5);
          }
          in.close();


        } else
        {
            System.out.println("!ERR! " + nu.getDateAndTime() + " LanguageManagement/readConfiguration -> COULDN'T FIND FILE ---> messages.nlg");
        }
    }

    public String getLanguageList(String s)
    {
        String s1 = "";
        for(Enumeration enumeration = languages.keys(); enumeration.hasMoreElements();)
        {
            String s2 = enumeration.nextElement().toString();
            String s3 = languages.get(s2).toString();
            if(s2.equals(s))
            {
                s1 = s1 + "<option value=\"" + s2 + "\" selected>" + s3 + "</option>\n";
            } else
            {
                s1 = s1 + "<option value=\"" + s2 + "\">" + s3 + "</option>\n";
            }
        }

        return s1;
    }

    public String getMessage(String s)
    {
        if(containsKey(language + "_" + s))
        {
            return get(language + "_" + s).toString();
        }
        if(containsKey(s))
        {
            return get(s).toString();
        } else
        {
            return "!LANG-TAG ->" + s + "<- MISSING!";
        }
    }
}
发表于 2003-4-7 14:00:39 | 显示全部楼层
全部完了吗?还是有下文?
 楼主| 发表于 2003-4-7 17:33:11 | 显示全部楼层
还有一些地方要改,有时间再贴,如果要用,我可以把改过的包放上来
发表于 2003-4-27 22:15:17 | 显示全部楼层

很希望你能共享出来。

也想研究研究。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表