2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.text.MessageFormat;
24 import java.util.Locale;
25 import java.util.ResourceBundle;
26 //import java.util.logging.Level;
27 //import java.util.logging.Logger;
29 import org.apache.log4j.Logger;
33 * @author David Roldan Martinez
34 * @author Thomas Abeel
38 public class MessageManager
41 // BH 2018 switched to org.apache.llog4j.Logger
43 private static ResourceBundle rb;
45 private static Logger log = Logger
46 .getLogger(MessageManager.class.getCanonicalName());
48 private static Locale loc;
54 /* Localize Java dialogs */
55 loc = Locale.getDefault();
56 // Locale.setDefault(loc);
57 /* Getting messages for GV */
58 log.info("Getting messages for lang: " + loc);
59 rb = ResourceBundle.getBundle("lang.Messages", loc);
60 // if (log.isLoggable(Level.FINEST))
62 // // this might take a while, so we only do it if it will be shown
63 // log.info("Language keys: " + rb.keySet()); // was FINEST
67 log.warn("Exception when initting Locale for i18n messages\n"
72 log.warn("Error when initting Locale for i18n messages\n"
79 public static String getString(String key)
81 String value = "[missing key] " + key;
84 value = rb.getString(key);
87 log.warn("I18N missing: " + loc + "\t" + key);
92 public static Locale getLocale()
97 public static String formatMessage(String key, Object... params)
99 return MessageFormat.format(rb.getString(key), params);
102 public static String formatMessage(String key, String[] params)
104 return MessageFormat.format(rb.getString(key), (Object[]) params);
108 * lookup and return a key given a root and a human-readable(ish) name that
109 * when combined might resolve to an i18n string. If the key doesn't resolve,
110 * then name is returned.if the key doesn't exist. Use this for
111 * programatically constructed keys that have have a human readable
112 * alternative used in the program (e.g. BLOSUM62 and label.score_blosum62)
118 public static String getStringOrReturn(String keyroot, String name)
120 String smkey = keyroot + name.toLowerCase().replaceAll(" ", "");
123 name = rb.getString(smkey);
124 } catch (Exception x)
126 log.info("I18N missing key with root " + keyroot + ": " + loc + "\t"
127 + smkey); // was FINEST