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:46:36 $
20 */
21 package net.sf.bloof.script.intl;
22
23
24 import java.util.Locale;
25 import java.util.MissingResourceException;
26 import java.util.ResourceBundle;
27 import java.util.logging.Logger;
28
29 /***
30 * This class manages the externalization of strings that will
31 * possiby be presented to the user.
32 * On default it loads the English text resources. It also can load
33 * language specific property files.
34 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
35 * @version $Id: Messages.java,v 1.1 2003/09/06 08:46:36 pekacki Exp $
36 */
37 public class Messages {
38 /***
39 * Returns the currenty available Languages
40 * @return Language[]
41 */
42 public static Language[] getAvailableLanguages() {
43 return AVAILABLE_LANGUAGES;
44 }
45
46 /***
47 * Returns the value for the specified key. key-value pairs are specivied
48 * in the resourcebundle properties file.
49 * @param aKey key of the requested string
50 * @return String
51 */
52 public static String getString(TextKey aKey) {
53 try {
54 return sCurrentLanguageBundle.getString(aKey.getName());
55 } catch (MissingResourceException aMissingEntry) {
56 sLogger.warning(
57 "Missing String "
58 + aKey
59 + " in "
60 + sCurrentLanguageBundle.getLocale().getLanguage()
61 + " bundle.");
62 if (sCurrentLanguageBundle != DEFAULT_LANGUAGE_BUNDLE) {
63 try {
64 return sCurrentLanguageBundle.getString(aKey.getName());
65 } catch (MissingResourceException aMissing) {
66 return "!missing!" + aKey + "!missing!";
67 }
68 } else {
69 return "!missing!" + aKey + "!missing!";
70 }
71 }
72 }
73 /***
74 * Sets a language for Bloof
75 * @param aLanguage the language that bloof should use for user output
76 */
77 public static void setLanguage(Language aLanguage) {
78 if (aLanguage == Language.GERMAN) {
79 sLogger.info("Setting language to GERMAN");
80 sCurrentLanguageBundle = ResourceBundle.getBundle(BUNDLE_BASE, Locale.GERMAN);
81 } else {
82 sLogger.info("Setting language to DEFAULT");
83 sCurrentLanguageBundle = DEFAULT_LANGUAGE_BUNDLE;
84 }
85
86 }
87 private static final Language[] AVAILABLE_LANGUAGES = { Language.ENGLISH, Language.GERMAN };
88 private static final String BUNDLE_BASE = net.sf.bloof.script.intl.Text.class.getName();
89 private static final ResourceBundle DEFAULT_LANGUAGE_BUNDLE =
90 ResourceBundle.getBundle(
91 BUNDLE_BASE,
92 Locale.ENGLISH,
93 net.sf.bloof.script.intl.Text.class.getClassLoader());
94 /***
95 * Newline constant
96 */
97 public static final String NL = "\n";
98 private static ResourceBundle sCurrentLanguageBundle = DEFAULT_LANGUAGE_BUNDLE;
99 private static Logger sLogger = Logger.getLogger(Messages.class.getName());
100 /***
101 * Whitespace constant
102 */
103 public static final String WS = " ";
104 }
This page was automatically generated by Maven