39 |
import java.util.List; |
import java.util.List; |
40 |
import java.util.Locale; |
import java.util.Locale; |
41 |
import java.util.Random; |
import java.util.Random; |
42 |
|
import java.util.WeakHashMap; |
43 |
|
|
44 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
45 |
|
|
62 |
public static final String LOCALECHANGE_PROPERTY = "localechange"; |
public static final String LOCALECHANGE_PROPERTY = "localechange"; |
63 |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
64 |
public static final String DEFAULT_KEY = "default"; |
public static final String DEFAULT_KEY = "default"; |
65 |
static final Logger log = Logger.getLogger(Translation.class); |
static final Logger LOGGER = Logger.getLogger(Translation.class); |
66 |
static String activeLang = Locale.getDefault().getLanguage(); |
static String activeLang = Locale.getDefault().getLanguage(); |
67 |
|
|
68 |
static protected List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(); |
static protected WeakHashSet<PropertyChangeListener> listeners = new WeakHashSet<PropertyChangeListener>( |
69 |
|
PropertyChangeListener.class); |
70 |
|
|
71 |
static { |
static { |
72 |
|
|
145 |
|
|
146 |
fireLocaleChangeEvents(); |
fireLocaleChangeEvents(); |
147 |
|
|
148 |
log.info("skrueger.i8n.Translation switched ActiveLang to " + newLang); |
LOGGER.info("skrueger.i8n.Translation switched ActiveLang to " |
149 |
|
+ newLang); |
150 |
} |
} |
151 |
|
|
152 |
/** |
/** |
178 |
put(DEFAULT_KEY, defaultTranslation); |
put(DEFAULT_KEY, defaultTranslation); |
179 |
} else |
} else |
180 |
for (String code : languages) { |
for (String code : languages) { |
181 |
if (code.equals(getActiveLang())) { |
// if (code.equals(getActiveLang())) { |
182 |
put(code, defaultTranslation); |
put(code, defaultTranslation); |
183 |
} |
// } |
184 |
} |
} |
185 |
} |
} |
186 |
|
|
231 |
eatUp = eatUp.substring(eatUp.indexOf("}") + 1); |
eatUp = eatUp.substring(eatUp.indexOf("}") + 1); |
232 |
} |
} |
233 |
} catch (Exception e) { |
} catch (Exception e) { |
234 |
log.warn("Error while reading the oneLineCode '" + oneLineCoded |
LOGGER.warn("Error while reading the oneLineCode '" + oneLineCoded |
235 |
+ "'", e); |
+ "'", e); |
236 |
log.warn("Translation will be empty!"); |
LOGGER.warn("Translation will be empty!"); |
237 |
} |
} |
238 |
} |
} |
239 |
|
|
287 |
|
|
288 |
/** |
/** |
289 |
* {@link PropertyChangeListener} can be registered to be informed when the |
* {@link PropertyChangeListener} can be registered to be informed when the |
290 |
* {@link Locale} changed. |
* {@link Locale} changed.<br> |
291 |
|
* The listeners are kept in a {@link WeakHashMap}, so you have to keep a |
292 |
|
* reference to the listener or it will be removed! |
293 |
* |
* |
294 |
* @param propertyChangeListener |
* @param propertyChangeListener |
295 |
|
* A {@link PropertyChangeListener} that will be called when |
296 |
|
* {@link #setActiveLang(String)} changes the language. |
297 |
*/ |
*/ |
298 |
public static void addLocaleChangeListener( |
public static void addLocaleChangeListener( |
299 |
PropertyChangeListener propertyChangeListener) { |
PropertyChangeListener propertyChangeListener) { |
301 |
} |
} |
302 |
|
|
303 |
/** |
/** |
304 |
|
* {@link PropertyChangeListener} can be registered to be informed when the |
305 |
|
* {@link Locale} changed.<br> |
306 |
|
* The listeners are kept in a {@link WeakHashMap}, so you have to keep a |
307 |
|
* reference to the listener or it will be removed! |
308 |
|
* |
309 |
|
* @param propertyChangeListener |
310 |
|
* A {@link PropertyChangeListener} that will be called when |
311 |
|
* {@link #setActiveLang(String)} changes the language. |
312 |
|
*/ |
313 |
|
public static boolean removeLocaleChangeListener( |
314 |
|
PropertyChangeListener propertyChangeListener) { |
315 |
|
return listeners.remove(propertyChangeListener); |
316 |
|
} |
317 |
|
|
318 |
|
/** |
319 |
* Informs all registered {@link PropertyChangeListener}s about a change of |
* Informs all registered {@link PropertyChangeListener}s about a change of |
320 |
* the the {@link Locale}. |
* the the {@link Locale}. |
321 |
*/ |
*/ |
334 |
* reference as long as you need the listener. |
* reference as long as you need the listener. |
335 |
*/ |
*/ |
336 |
public void addTranslationChangeListener(ActionListener actionListener) { |
public void addTranslationChangeListener(ActionListener actionListener) { |
337 |
actionListeners.add(actionListener); |
if (actionListeners.add(actionListener)) { |
338 |
|
LOGGER |
339 |
|
.debug("registering a new translationChangeActionListener in the WeakHashSet"); |
340 |
|
} |
341 |
} |
} |
342 |
|
|
343 |
/** |
/** |