01: /*
02: JSPWiki - a JSP-based WikiWiki clone.
03:
04: Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
05:
06: This program is free software; you can redistribute it and/or modify
07: it under the terms of the GNU Lesser General Public License as published by
08: the Free Software Foundation; either version 2.1 of the License, or
09: (at your option) any later version.
10:
11: This program is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU Lesser General Public License for more details.
15:
16: You should have received a copy of the GNU Lesser General Public License
17: along with this program; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package com.ecyrd.jspwiki.i18n;
21:
22: import java.util.Locale;
23: import java.util.MissingResourceException;
24: import java.util.ResourceBundle;
25:
26: import com.ecyrd.jspwiki.WikiEngine;
27:
28: /**
29: * Manages all internationalization in JSPWiki.
30: *
31: * @author Janne Jalkanen
32: * @since 2.6
33: */
34: public class InternationalizationManager {
35: /** The name of the ResourceBundle which contains any and all JSPWiki core
36: * resource strings. It's value is {@value}.
37: */
38: public static final String CORE_BUNDLE = "CoreResources";
39:
40: // public static final String JSPWIKI_BUNDLE = "jspwiki";
41: // public static final String PLUGINS_BUNDLE = "plugins";
42:
43: /**
44: * Constructs a new InternationalizationManager.
45: *
46: * @param engine To which engine this belongs to
47: */
48: public InternationalizationManager(WikiEngine engine) {
49: }
50:
51: /**
52: * Returns a String from the CORE_BUNDLE using English as the default
53: * locale.
54: *
55: * @param key Key to find
56: * @return The English string
57: * @throws MissingResourceException If there is no such key
58: */
59: public String get(String key) throws MissingResourceException {
60: return get(CORE_BUNDLE, Locale.ENGLISH, key);
61: }
62:
63: /**
64: * Finds a resource bundle.
65: *
66: * @param bundle The ResourceBundle to find. Must exist.
67: * @param locale The Locale to use. Set to null to get the default locale.
68: * @return A localized string
69: * @throws MissingResourceException If the key cannot be located at all, even from the default locale.
70: */
71: public ResourceBundle getBundle(String bundle, Locale locale)
72: throws MissingResourceException {
73: if (locale == null)
74: locale = Locale.getDefault();
75:
76: ResourceBundle b = ResourceBundle.getBundle(bundle, locale);
77:
78: return b;
79: }
80:
81: /**
82: * If you are too lazy to open your own bundle, use this method
83: * to get a string simply from a bundle.
84: * @param bundle Which bundle the string is in
85: * @param locale Locale to use - null for default
86: * @param key Which key to use.
87: * @return A localized string (or from the default language, if not found)
88: * @throws MissingResourceException If the key cannot be located at all, even from the default locale.
89: */
90: public String get(String bundle, Locale locale, String key)
91: throws MissingResourceException {
92: return getBundle(bundle, locale).getString(key);
93: }
94: }
|