001: /*
002:
003: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
004:
005: * for visualizing and manipulating spatial features with geometry and attributes.
006:
007: *
008:
009: * Copyright (C) 2003 Vivid Solutions
010:
011: *
012:
013: * This program is free software; you can redistribute it and/or
014:
015: * modify it under the terms of the GNU General Public License
016:
017: * as published by the Free Software Foundation; either version 2
018:
019: * of the License, or (at your option) any later version.
020:
021: *
022:
023: * This program is distributed in the hope that it will be useful,
024:
025: * but WITHOUT ANY WARRANTY; without even the implied warranty of
026:
027: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
028:
029: * GNU General Public License for more details.
030:
031: *
032:
033: * You should have received a copy of the GNU General Public License
034:
035: * along with this program; if not, write to the Free Software
036:
037: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
038:
039: *
040:
041: * For more information, contact:
042:
043: *
044:
045: * Vivid Solutions
046:
047: * Suite #1A
048:
049: * 2328 Government Street
050:
051: * Victoria BC V8T 5G5
052:
053: * Canada
054:
055: *
056:
057: * (250)385-6040
058:
059: * www.vividsolutions.com
060:
061: */
062:
063: package de.fho.jump.pirol.utilities.i18n;
064:
065: import java.text.MessageFormat;
066: import java.util.Hashtable;
067: import java.util.Locale;
068: import java.util.ResourceBundle;
069:
070: import com.vividsolutions.jump.I18N;
071: import com.vividsolutions.jump.workbench.JUMPWorkbench;
072:
073: import de.fho.jump.pirol.utilities.debugOutput.DebugUserIds;
074: import de.fho.jump.pirol.utilities.debugOutput.PersonalLogger;
075:
076: /**
077:
078: * Class taken from the RasterImage-i18N PlugIn of Jan Ruzicka (jan.ruzicka@vsb.cz) and modified for PIROL.
079:
080: */
081:
082: public final class I18NPlug {
083:
084: protected static PersonalLogger logger = new de.fho.jump.pirol.utilities.debugOutput.PersonalLogger(
085: DebugUserIds.ALL);
086:
087: public static boolean jumpi18n = true;
088:
089: private static Hashtable plugInResourceBundle = new Hashtable();
090:
091: /**
092:
093: * Set plugin I18N resource file
094:
095: * Tries to use locale set in command line (if set)
096:
097: * @param pluginName (path + name)
098:
099: * @param bundle reference of the bundle file
100:
101: */
102:
103: public static void setPlugInRessource(String pluginName,
104: String bundle) {
105:
106: try {
107:
108: String local = JUMPWorkbench.I18N_SETLOCALE;
109:
110: } catch (java.lang.NoSuchFieldError s) {
111:
112: jumpi18n = false;
113:
114: }
115:
116: if (jumpi18n == true) {
117:
118: if (JUMPWorkbench.I18N_SETLOCALE == "") {
119:
120: // No locale has been specified at startup: choose default locale
121:
122: I18N.plugInsResourceBundle.put(pluginName,
123: ResourceBundle.getBundle(bundle));
124:
125: //logger.printDebug(I18N.plugInsResourceBundle.get(pluginName)+" "+bundle);
126:
127: }
128:
129: else {
130:
131: String lang = JUMPWorkbench.I18N_SETLOCALE.split("_")[0];
132:
133: try {
134:
135: String country = JUMPWorkbench.I18N_SETLOCALE
136: .split("_")[1];
137:
138: Locale locale = new Locale(lang, country);
139:
140: I18N.plugInsResourceBundle.put(pluginName,
141: ResourceBundle.getBundle(bundle, locale));
142:
143: //logger.printDebug(I18N.plugInsResourceBundle.get(pluginName)+" "+bundle+" "+locale);
144:
145: } catch (java.lang.ArrayIndexOutOfBoundsException e) {
146:
147: Locale locale = new Locale(lang);
148:
149: I18N.plugInsResourceBundle.put(pluginName,
150: ResourceBundle.getBundle(bundle, locale));
151:
152: //LOG.debug(I18N.plugInsResourceBundle.get(pluginName)+" "+bundle+" "+locale);
153:
154: }
155:
156: }
157:
158: }
159:
160: else {
161:
162: // in this case we use the default .properties file (en)
163:
164: I18NPlug.plugInResourceBundle.put(pluginName,
165: ResourceBundle.getBundle(bundle));
166:
167: //logger.printDebug(I18NPlug.plugInResourceBundle.get(pluginName)+" cz.vsb.gisak.jump.rasterimage");
168:
169: }
170:
171: }
172:
173: /**
174:
175: * Process text with the locale 'pluginName_<locale>.properties' file
176:
177: *
178:
179: * @param pluginName (path + name)
180:
181: * @param label
182:
183: * @return i18n label
184:
185: */
186:
187: public static String get(String pluginName, String label)
188:
189: {
190:
191: if (jumpi18n == true) {
192:
193: /*
194:
195: logger.printDebug(I18N.plugInsResourceBundle.get(pluginName)+" "+label
196:
197: + ((ResourceBundle)I18N.plugInsResourceBundle
198:
199: .get(pluginName))
200:
201: .getString(label));
202:
203: */
204:
205: return ((ResourceBundle) I18N.plugInsResourceBundle
206:
207: .get(pluginName))
208:
209: .getString(label);
210:
211: }
212:
213: return ((ResourceBundle) I18NPlug.plugInResourceBundle
214:
215: .get(pluginName))
216:
217: .getString(label);
218:
219: }
220:
221: /**
222:
223: * Process text with the locale 'pluginName_<locale>.properties' file
224:
225: *
226:
227: * @param pluginName (path + name)
228:
229: * @param label with argument insertion : {0}
230:
231: * @param objects
232:
233: * @return i18n label
234:
235: */
236:
237: public static String getMessage(String pluginName, String label,
238: Object[] objects) {
239:
240: if (jumpi18n == true) {
241:
242: MessageFormat mf = new MessageFormat(
243: ((ResourceBundle) I18N.plugInsResourceBundle
244:
245: .get(pluginName))
246:
247: .getString(label));
248:
249: return mf.format(objects);
250:
251: }
252:
253: MessageFormat mf = new MessageFormat(
254: ((ResourceBundle) I18NPlug.plugInResourceBundle
255:
256: .get(pluginName))
257:
258: .getString(label));
259:
260: return mf.format(objects);
261:
262: }
263:
264: }
|