1 19 20 package org.lucane.client.util; 21 22 import java.io.*; 23 import java.net.*; 24 import java.util.*; 25 26 import javax.swing.UIManager ; 27 28 import org.lucane.client.Client; 29 import org.lucane.common.Logging; 30 31 34 public class Translation 35 { 36 private static ResourceBundle bundle; 37 private static ResourceBundle defaultBundle; 38 39 43 public static void setLocale(String lang) 44 { 45 Locale.setDefault(new Locale(lang)); 46 try { 47 InputStream is = new URL(getDirectory() + "messages/messages.properties").openStream(); 48 Translation.bundle = new PropertyResourceBundle(is); 49 Translation.defaultBundle = Translation.bundle; 50 } catch(Exception e) { 51 Translation.bundle = null; 52 Translation.defaultBundle = null; 53 } 54 55 try { 56 InputStream is = new URL(getDirectory() + "messages/messages_" + lang + ".properties").openStream(); 57 Translation.bundle = new PropertyResourceBundle(is); 58 } catch(Exception e) { 59 if(Translation.bundle == null) 60 Logging.getLogger().info("unable to set language"); 61 } 62 63 try { 64 if(Translation.bundle != null) 65 Translation.changeUIMessages(); 66 } catch(UnsatisfiedLinkError ule) { 67 } 69 } 70 71 77 public static String tr(String origin) 78 { 79 try { 80 return bundle.getString(origin); 81 } catch(Exception e) { 82 try { 83 return defaultBundle.getString(origin); 84 } catch(Exception e2) { 85 return origin; 86 } 87 } 88 } 89 90 95 private static String getDirectory() 96 { 97 String url = "jar:file:///" 98 + System.getProperty("user.dir") 99 + "/lib/lucane-client-" + Client.VERSION +".jar!/"; 100 101 return url.replace('\\', '/'); 102 } 103 104 107 private static void changeUIMessages() 108 throws UnsatisfiedLinkError 109 { 110 String [] messages = { 111 "FileChooser.acceptAllFileFilterText", 112 "FileChooser.cancelButtonText", 113 "FileChooser.cancelButtonToolTipText", 114 "FileChooser.detailsViewButtonToolTipText", 115 "FileChooser.directoryDescriptionText", 116 "FileChooser.fileDescriptionText", 117 "FileChooser.fileNameLabelText", 118 "FileChooser.filesOfTypeLabelText", 119 "FileChooser.helpButtonText", 120 "FileChooser.helpButtonToolTipText", 121 "FileChooser.homeFolderToolTipText", 122 "FileChooser.listViewButtonToolTipText", 123 "FileChooser.lookInLabelText", 124 "FileChooser.newFolderErrorText", 125 "FileChooser.newFolderToolTipText", 126 "FileChooser.openButtonText", 127 "FileChooser.openButtonToolTipText", 128 "FileChooser.saveButtonText", 129 "FileChooser.saveButtonToolTipText", 130 "FileChooser.updateButtonText", 131 "FileChooser.updateButtonToolTipText", 132 "FileChooser.upFolderToolTipText"}; 133 134 for(int i=0;i<messages.length;i++) 135 UIManager.put(messages[i], Translation.tr(messages[i])); 136 } 137 } 138 | Popular Tags |