1 package net.sf.openrocket.l10n;
3 import java.util.HashSet;
4 import java.util.Locale;
5 import java.util.MissingResourceException;
8 import net.sf.openrocket.gui.main.ExceptionHandler;
11 * A translator that suppresses MissingResourceExceptions and handles them gracefully.
12 * For every missing key this class calls the exception handler exactly once, and
13 * returns the key itself as the translation.
15 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17 public class ExceptionSuppressingTranslator implements Translator {
19 private static final Set<String> errors = new HashSet<String>();
21 static int failures = 0;
23 private final Translator translator;
30 * @param translator the translator to use
32 public ExceptionSuppressingTranslator(Translator translator) {
33 this.translator = translator;
39 public String get(String key) {
41 return translator.get(key);
42 } catch (MissingResourceException e) {
51 private static synchronized void handleError(String key, MissingResourceException e) {
52 if (errors.add(key)) {
54 ExceptionHandler.handleErrorCondition("Can not find translation for '" + key + "' locale=" + Locale.getDefault(), e);