public class MyResource extends ResourceBundle { private Hashtable res = null; public MyResource() { res = new Hashtable(); res.put("TestKey","English Variant"); } public Enumeration getKeys() { return res.keys(); } protected Object handleGetObject(String key) throws java.util.MissingResourceException { return res.get(key); } } public class MyResource_ru_RU extends ResourceBundle { private Hashtable res = null; public MyResource_ru_RU() { res = new Hashtable(); res.put("TestKey","Русский варинат"); } public Enumeration getKeys() { return res.keys(); } protected Object handleGetObject(String key) throws java.util.MissingResourceException { return res.get(key); } } public class Test { public Test() { } public static void main(String[] args) { Test test = new Test(); ResourceBundle rb = ResourceBundle.getBundle("experiment.MyResource",Locale.getDefault()); System.out.println(rb.getString("TestKey")); rb = ResourceBundle.getBundle("experiment.MyResource", new Locale("ru","RU")); System.out.println(rb.getString("TestKey")); } } |
Пример 14.29. |
Закрыть окно |