3 import java.text.MessageFormat;
4 import java.util.Locale;
5 import java.util.ResourceBundle;
6 import java.util.logging.Level;
7 import java.util.logging.Logger;
11 * @author David Roldan Martinez
12 * @author Thomas Abeel
16 public class MessageManager {
18 private static ResourceBundle rb;
20 private static Logger log=Logger.getLogger(MessageManager.class.getCanonicalName());
22 private static Locale loc;
28 /* Localize Java dialogs */
29 loc = Locale.getDefault();
30 // Locale.setDefault(loc);
31 /* Getting messages for GV */
32 log.info("Getting messages for lang: "+loc);
33 rb = ResourceBundle.getBundle("lang.Messages", loc);
34 if (log.isLoggable(Level.FINEST)) {
35 // this might take a while, so we only do it if it will be shown
36 log.finest("Language keys: "+rb.keySet());
38 } catch (Exception q) {
39 log.warning("Exception when initting Locale for i18n messages\n"+q.getMessage());
44 log.warning("Error when initting Locale for i18n messages\n"+v.getMessage());
51 public static String getString(String key){
52 String value = "[missing key] " + key;
54 value = rb.getString(key);
56 log.warning("I18N missing: "+loc+"\t"+key);
61 public static Locale getLocale() {
64 public static String formatMessage(String key, Object... params){
65 return MessageFormat.format(rb.getString(key), (Object[]) params);
69 * lookup and return a key given a root and a human-readable(ish) name that when combined might resolve to an i18n string.
70 * If the key doesn't resolve, then name is returned.if the key doesn't exist.
71 * Use this for programatically constructed keys that have have a human readable alternative used in the program (e.g. BLOSUM62 and label.score_blosum62)
76 public static String getStringOrReturn(String keyroot, String name)
78 String smkey = keyroot
79 + name.toLowerCase().replaceAll(" ", "");
81 name = rb.getString(smkey);
84 log.finest("I18N missing key with root "+keyroot+": "+loc+"\t"+smkey);