View Javadoc

1   /*
2    * Messages.java
3    * Copyright (C) 2004  Pal Brattberg <pal@eminds.se>
4    * 
5    * This program is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   * 
19   * File created: 2004-nov-13
20   */
21  package se.perfectfools.localizer.i18n;
22  
23  import java.util.MissingResourceException;
24  import java.util.ResourceBundle;
25  
26  /***
27   * This class handles i18n for ezloc itself.
28   * 
29   * @author P&aring;l Brattberg &lt; <a href="mailto:pal@eminds.se">pal@eminds.se </a>&gt;
30   * @version $Id: Messages.java,v 1.2 2004/11/13 13:34:48 pal Exp $
31   */
32  public class Messages {
33  
34      private static final String BUNDLE_NAME = "messages"; //$NON-NLS-1$
35      private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
36  
37      protected Messages() {
38      }
39  
40      /***
41       * Get a translated string for the current locale.
42       * 
43       * @param key The key for the String to translate
44       * @return The translated string, or <code>!<em>key</em>!</code> if no
45       * translation was found.
46       */
47      public static String getString(String key) {
48          try {
49              return RESOURCE_BUNDLE.getString(key);
50          } catch (MissingResourceException e) {
51              return '!' + key + '!';
52          }
53      }
54  }