View Javadoc

1   /*
2    * Created on May 20, 2005
3    *
4    * Default I18nHelper implementation.
5    */
6   package net.sf.tlc.core.impl;
7   
8   import java.util.Locale;
9   import java.util.ResourceBundle;
10  
11  import net.sf.tlc.core.I18nHelper;
12  
13  /***
14   * Default I18nHelper implementation.
15   * 
16   * @author aisrael
17   */
18  public class DefaultI18nHelper implements I18nHelper {
19  
20      private Locale currentLocale;
21  
22      private ResourceBundle currentResourceBundle;
23  
24      private final String bundleName;
25  
26      /***
27       * Default constructor
28       * 
29       * @param bundleName
30       *            the resource bundle base name
31       */
32      public DefaultI18nHelper(final String bundleName) {
33          this.bundleName = bundleName;
34          setCurrentLocale(Locale.getDefault());
35      }
36  
37      /***
38       * (non-Javadoc)
39       * 
40       * @see net.sf.tlc.core.I18nHelper#setCurrentLocale(java.util.Locale)
41       */
42      public final void setCurrentLocale(final Locale locale) {
43          this.currentLocale = locale;
44          currentResourceBundle = ResourceBundle.getBundle(bundleName, this.currentLocale);
45      }
46  
47      /***
48       * (non-Javadoc)
49       * 
50       * @see net.sf.tlc.core.I18nHelper#getCurrentLocale()
51       */
52      public final Locale getCurrentLocale() {
53          return this.currentLocale;
54      }
55  
56      /***
57       * (non-Javadoc)
58       * 
59       * @see net.sf.tlc.core.I18nHelper#getMessage(java.lang.String)
60       */
61      public final String getMessage(final String key) {
62          return currentResourceBundle.getString(key);
63      }
64  
65  }