826220679@qq.com
10 天以前 176cfa1a137d2050d4e8a105dfdbdc8f1b32afb2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package publicsWay;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
 
import dell_targets.Dell_SystemConfiguration;
 
public class Languages {
    // Ð޸ĺóµÄ×ÊÔ´¼ÓÔØ·½·¨
    public static ResourceBundle getCurrentMessages() {
        // ¸ù¾ÝϵͳÅäÖþö¶¨ÓïÑÔ
        Locale locale = "1".equals(Dell_SystemConfiguration.language) ? 
                Locale.ENGLISH : Locale.SIMPLIFIED_CHINESE;
        
        // Ê¹ÓÃÓëWindows.javaÏàͬµÄ¼ÓÔØÂß¼­
        String fileName = locale.equals(Locale.ENGLISH) ? 
                "Messages_en.properties" : "Messages_zh.properties";
        
        File langFile = new File("systemfile/" + fileName);
        
        if (!langFile.exists()) {
            System.err.println("ĬÈÏ×ÊÔ´ÎļþδÕÒµ½: " + langFile.getAbsolutePath());
            try {
                return ResourceBundle.getBundle("systemfile.Messages", locale);
            } catch (Exception e) {
                System.err.println("ºó±¸×ÊÔ´¼ÓÔØÊ§°Ü: " + e.getMessage());
                // ·µ»Ø¿Õ°ü±ÜÃâ±ÀÀ£
                return new ResourceBundle() {
                    @Override
                    protected Object handleGetObject(String key) {
                        return "!" + key + "!";
                    }
                    @Override
                    public Enumeration<String> getKeys() {
                        return java.util.Collections.emptyEnumeration();
                    }
                };
            }
        }
        
        try (InputStream inputStream = new FileInputStream(langFile)) {
            return new PropertyResourceBundle(inputStream);
        } catch (IOException e) {
            System.err.println("ÎÞ·¨¼ÓÔØ×ÊÔ´Îļþ: " + e.getMessage());
            return ResourceBundle.getBundle("systemfile.Messages", locale);
        }
    }
}