1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: Messages.java,v $
19 Created on $Date: 2003/09/06 08:35:09 $
20 */
21 package net.sf.bloof.util.intl;
22
23 import java.util.Locale;
24 import java.util.MissingResourceException;
25 import java.util.ResourceBundle;
26 import java.util.logging.Logger;
27
28 /***
29 * This class manages the externalization of strings that will
30 * possiby be presented to the user.
31 * On default it loads the English text resources. It also can load
32 * language specific property files.
33 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
34 * @version $Id: Messages.java,v 1.10 2003/09/06 08:35:09 pekacki Exp $
35 */
36 public class Messages {
37 /***
38 * Returns the currenty available Languages
39 * @return Language[]
40 */
41 public static Language[] getAvailableLanguages() {
42 return AVAILABLE_LANGUAGES;
43 }
44
45 /***
46 * Returns the current Locale
47 * @return current Locale
48 */
49 public static Locale getCurrentLocale() {
50 return sCurrentLocale;
51 }
52
53 /***
54 * Returns the value for the specified key. key-value pairs are specivied
55 * in the resourcebundle properties file.
56 * @param aKey key of the requested string
57 * @return String
58 */
59 public static String getString(TextKey aKey) {
60 try {
61 return sCurrentLanguageBundle.getString(aKey.getName());
62 } catch (MissingResourceException aMissingEntry) {
63 sLogger.warning(
64 "Missing String "
65 + aKey
66 + " in "
67 + sCurrentLanguageBundle.getLocale().getLanguage()
68 + " bundle.");
69 if (sCurrentLanguageBundle != DEFAULT_LANGUAGE_BUNDLE) {
70 try {
71 return sCurrentLanguageBundle.getString(aKey.getName());
72 } catch (MissingResourceException aMissing) {
73 return "?" + aKey + "?";
74 }
75 } else {
76 return "?" + aKey + "?";
77 }
78 }
79 }
80 /***
81 * Sets a language for Bloof
82 * @param aLanguage the language that bloof should use for user output
83 */
84 public static void setLanguage(Language aLanguage) {
85 if (aLanguage == Language.GERMAN) {
86 sLogger.info("Setting language to GERMAN");
87 sCurrentLanguageBundle = ResourceBundle.getBundle(BUNDLE_BASE, Locale.GERMAN);
88 } else {
89 sLogger.info("Setting language to DEFAULT");
90 sCurrentLanguageBundle = DEFAULT_LANGUAGE_BUNDLE;
91 }
92
93 }
94 private static final Language[] AVAILABLE_LANGUAGES = { Language.ENGLISH, Language.GERMAN };
95 private static final String BUNDLE_BASE = net.sf.bloof.util.intl.Text.class.getName();
96 private static final ResourceBundle DEFAULT_LANGUAGE_BUNDLE =
97 ResourceBundle.getBundle(
98 BUNDLE_BASE,
99 Locale.ENGLISH,
100 net.sf.bloof.util.intl.Text.class.getClassLoader());
101 /***
102 * Newline constant
103 */
104 public static final String NL = "\n";
105 private static Locale sCurrentLocale = Locale.ENGLISH;
106 private static ResourceBundle sCurrentLanguageBundle = DEFAULT_LANGUAGE_BUNDLE;
107 private static Logger sLogger = Logger.getLogger(Messages.class.getName());
108 /***
109 * Whitespace constant
110 */
111 public static final String WS = " ";
112 static {
113 Locale.setDefault(Locale.ENGLISH);
114 }
115 }
This page was automatically generated by Maven