3 import java.util.Locale;
4 import java.util.MissingResourceException;
5 import java.util.ResourceBundle;
8 * Manager for all internationalization
9 * Responsible for loading property files
10 * and delivering language-specific texts
12 public abstract class I18nManager
14 private static final String BUNDLE_NAME = "tim.prune.lang.prune-texts";
15 private static final Locale BACKUP_LOCALE = new Locale("en", "GB");
17 private static ResourceBundle EnglishTexts = null;
18 private static ResourceBundle ExtraTexts = null;
22 * Initialize the library
23 * using the (optional) locale
25 public static void init(Locale inLocale)
27 // Load English texts first to use as defaults
28 EnglishTexts = ResourceBundle.getBundle(BUNDLE_NAME, BACKUP_LOCALE);
30 // Get bundle for selected locale, if any
33 ExtraTexts = ResourceBundle.getBundle(BUNDLE_NAME, inLocale);
37 // locale is null so just use the system default
38 ExtraTexts = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault());
44 * Lookup the given key and return the associated text
45 * @param inKey key to lookup
46 * @return associated text, or the key if not found
48 public static String getText(String inKey)
51 // look in extra texts if available
52 if (ExtraTexts != null)
56 value = ExtraTexts.getString(inKey);
57 if (value != null && !value.equals(""))
60 catch (MissingResourceException mre) {}
62 // look in english texts
63 if (EnglishTexts != null)
67 value = EnglishTexts.getString(inKey);
68 if (value != null && !value.equals(""))
71 catch (MissingResourceException mre) {}
73 // return the key itself