import java.util.MissingResourceException;
import java.util.Properties;
import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.swing.KeyStroke;
import net.pterodactylus.util.io.Closer;
+import net.pterodactylus.util.logging.Logging;
/**
* Class that handles i18n.
- *
+ *
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
*/
public class I18n {
+ /** Logger. */
+ private static final Logger logger = Logging.getLogger(I18n.class.getName());
+
/** List of I18nables that are notified when the language changes. */
private static final List<I18nable> i18nables = new ArrayList<I18nable>();
/**
* Returns the translated value for a key. The translated values may contain
* placeholders that are replaced with the given parameters.
- *
+ *
* @see MessageFormat
* @param key
* The key to get
String value = null;
value = currentLanguage.getProperty(key);
if (value == null) {
- System.err.println("please fix “" + key + "”!");
+ logger.log(Level.WARNING, "please fix “" + key + "”!", new Throwable());
+ /* TODO - replace with value when done! */
return null;
}
if ((parameters != null) && (parameters.length > 0)) {
* Returns the keycode from the value of the given key. You can specify the
* constants in {@link KeyEvent} in the properties file, e.g. VK_S for the
* keycode ‘s’ when used for mnemonics.
- *
+ *
* @param key
* The key under which the keycode is stored
* @return The keycode
/**
* Returns a key stroke for use with swing accelerators.
- *
+ *
* @param key
* The key of the key stroke
* @return The key stroke, or <code>null</code> if no key stroke could be
modifierMask |= InputEvent.SHIFT_DOWN_MASK;
} else {
if (keyToken.startsWith("VK_")) {
+ if (keyToken.equals("VK_UNDEFINED")) {
+ return null;
+ }
try {
Field field = KeyEvent.class.getField(keyToken);
return KeyStroke.getKeyStroke(field.getInt(null), modifierMask);
/**
* Sets the current locale.
- *
+ *
* @param newLocale
* The new locale to use
*/
/**
* Sets the current locale.
- *
+ *
* @param newLocale
* The new locale to use
* @param notify
/**
* Returns the current locale.
- *
+ *
* @return The current locale
*/
public static Locale getLocale() {
/**
* Finds all available locales.
- *
+ *
* @return All available locales
*/
public static List<Locale> findAvailableLanguages() {
/**
* Registers the given I18nable to be updated when the language is changed.
- *
+ *
* @param i18nable
* The i18nable to register
*/
/**
* Deregisters the given I18nable to be updated when the language is
* changed.
- *
+ *
* @param i18nable
* The i18nable to register
*/
* Notifies all registered {@link I18nable}s that the language was changed.
*/
private static void notifyI18nables() {
- for (I18nable i18nable: i18nables) {
+ for (I18nable i18nable : i18nables) {
i18nable.updateI18n();
}
}