01: package simpleorm.simplewebapp.core;
02:
03: import java.util.ResourceBundle;
04: import java.util.MissingResourceException;
05: import java.text.NumberFormat;
06:
07: /**
08: * Simple wrapper for resource bundles etc.
09: * Does not handle different locale yet, that requires a little care with caching the bundles.
10: */
11: public class WI18n {
12: // http://www.java2java.com/Code/Java/Servlets/ServletLocalization.htm
13: //Locale locale = request.getLocale();
14: //NumberFormat nft = NumberFormat.getPercentInstance(locale);
15: //String formatted = nft.format(0.51);
16:
17: static ResourceBundle bundle;
18:
19: WI18n(WPage page) {
20: }
21:
22: public String translate(String key) {
23: if (bundle == null)
24: bundle = ResourceBundle.getBundle("prompts");// , locale);
25:
26: String res = null;
27: try {
28: res = "!" + bundle.getString(key);
29: } catch (MissingResourceException ex) {
30: // key not found, res will still be null
31: }
32: if (res == null)
33: res = "?" + key;
34: return res;
35: }
36: }
|