文件中好多这样的代码。如何才能显示正常的汉字呢?

解决方案 »

  1.   

    public class Translate { private String language = "en";
    private String country = "US";
    private Locale currentLocale;
    private ResourceBundle messages;
    private ResourceBundle labels;
    private ResourceBundle menu;
    private ResourceBundle helpMessages;
    private ResourceBundle devInfo;
    private static Translate me; static {
    me = new Translate("en", "US"); } /**
     * 
     * @param l
     * @param c
     */
    public Translate(String l, String c) {
    setLocale(l, c);
    me = this;
    } public static synchronized Translate getInstance() {
    return me;
    } public String getLanguage() {
    return language;
    } public String getCountry() {
    return country;
    } /**
     * Reset the Local
     * @param l
     * @param c
     */
    public void setLocale(String l, String c) {
    language = l;
    country = c; currentLocale = new Locale(language, country); try {
    messages =
    ResourceBundle.getBundle("MessagesBundle", currentLocale);
    labels = ResourceBundle.getBundle("LabelsBundle", currentLocale);
    //menu = ResourceBundle.getBundle("MenuMnemonic", currentLocale);
    menu = ResourceBundle.getBundle("MenuMnemonic");
    helpMessages = ResourceBundle.getBundle("HelpMessagesBundle", currentLocale);
    devInfo = ResourceBundle.getBundle("DevInfoBundle");
    } catch (Exception e) {
    e.printStackTrace();
    } } public String getMessage(String s) throws MissingResourceException {
    //return (messages.getString(s));
    String messageName = s; try {
    messageName = messages.getString(s);
    } catch (MissingResourceException mrex) {
    System.err.println(mrex.getLocalizedMessage());
    } finally {
    return messageName;
    }
    } public String getLabel(String s) throws MissingResourceException { //return (labels.getString(s));
    String labelName = s; try {
    labelName = labels.getString(s);
    } catch (MissingResourceException mrex) {
    System.err.println(mrex.getLocalizedMessage());
    } finally {
    return labelName;
    } } public char getMenuMnemonic(String s) throws MissingResourceException {
    char menuM = s.charAt(0);
    try {
    menuM = menu.getString(s).charAt(0);
    } catch (MissingResourceException mrex) {
    System.err.println(mrex.getLocalizedMessage());
    } finally {
    return menuM;
    }
    }

    public String getHelpMessage(String s) throws MissingResourceException {
    //return (messages.getString(s));
    String messageName = s; try {
    messageName = helpMessages.getString(s);
    } catch (MissingResourceException mrex) {
    System.err.println(mrex.getLocalizedMessage());
    } finally {
    return messageName;
    }
    } static public void main(String[] args) { Translate ts;
    if (args.length == 0) {
    ts = new Translate("en", "US");
    } else {
    ts = new Translate("zh", "TW");
    } System.out.println(ts.getMessage("TESTING"));
    System.out.println(ts.getLabel("TESTING"));
    ts.setLocale("zh", "TW");
    System.out.println(ts.getMessage("TESTING"));
    System.out.println(ts.getLabel("TESTING"));
    } /**
     * @param string
     * @return
     */
    public String getDevInfo(String s) {
    // TODO Auto-generated method stub
    //return null;
    String messageName = s; try {
    messageName = devInfo.getString(s);
    } catch (MissingResourceException mrex) {
    System.err.println(mrex.getLocalizedMessage());
    } finally {
    return messageName;
    }
    }
    }
      

  2.   

    you can use the class like this
    this.translator.getLabel("CommonButton-Refresh");
      

  3.   

    一楼正解,使用ResourceBundle来国际化
      

  4.   

    可不可以直接使用Prpertites,不行么?
      

  5.   

    java.util.Properties加载这个文件,然后想怎么操作就怎么操作吧