Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 53 54 package org.swixml; 55 56 import java.util.Locale ; 57 import java.util.MissingResourceException ; 58 import java.util.ResourceBundle ; 59 60 69 public class Localizer { 70 private Locale locale = Locale.getDefault(); 71 private String bundleName; 72 private ResourceBundle bundle; 73 private ClassLoader cl = Localizer.class.getClassLoader(); 74 75 81 public String getString( final String key ) { 82 if (!isUsable()) return key; 83 String s; 84 try { 85 s = bundle.getString( key ); 86 } catch (Exception e) { 87 s = key; } 89 return s; 90 } 91 92 96 public void setLocale( Locale locale ) { 97 if (locale==null) { 98 this.locale= null; 99 this.bundle = null; 100 this.bundleName = null; 101 } else if (this.locale != locale) { 102 this.locale = locale; 103 setResourceBundle( bundleName ); 104 } 105 } 106 107 111 public void setResourceBundle( String bundleName ) throws MissingResourceException { 112 this.bundleName = bundleName; 113 if (locale==null) { 114 locale= Locale.getDefault(); 115 } 116 if (bundleName != null) { 117 bundle = ResourceBundle.getBundle( bundleName, locale, cl ); 118 } else { 119 bundle = null; 120 } 121 } 122 123 127 public boolean isUsable() { 128 return (locale!=null && bundle!=null); 129 } 130 131 134 public ClassLoader getClassLoader() { 135 return cl; 136 } 137 138 143 void setClassLoader( ClassLoader cl ) { 144 this.cl = cl; 145 } 146 } 147
| Popular Tags
|