65 |
|
|
66 |
private static final long serialVersionUID = -347702744122305245L; |
private static final long serialVersionUID = -347702744122305245L; |
67 |
|
|
68 |
public static final String LOCALECHANGE_PROPERTY = "localechange"; |
public static final String LOCALE_CHANGE_PROPERTY = "localechange"; |
69 |
public static final String ACTIVELANG_CHANGE_PROPERTY = "activelangchange"; |
public static final String ACTIVELANG_CHANGE_PROPERTY = "activelangchange"; |
70 |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
public static final String NO_TRANSLATION = "NO TRANSLATION"; |
71 |
public static final String DEFAULT_KEY = "default"; |
public static final String DEFAULT_KEY = "default"; |
160 |
Locale newLocale = new Locale(newLang); |
Locale newLocale = new Locale(newLang); |
161 |
if (setDefaultLocale) { |
if (setDefaultLocale) { |
162 |
|
|
163 |
Locale.setDefault(newLocale); |
setDefaultLocale(newLocale); |
|
/** |
|
|
* Setting default locale for Swing JComponents to work around bug |
|
|
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4884480 |
|
|
*/ |
|
|
JComponent.setDefaultLocale(newLocale); |
|
|
|
|
|
fireLocaleChangeEvents(); |
|
164 |
|
|
165 |
LOGGER.info(Translation.class.getName() |
LOGGER.info(Translation.class.getName() |
166 |
+ " switched ActiveLang and Locale to " + newLang); |
+ " switched ActiveLang and Locale to " + newLang); |
373 |
|
|
374 |
/** |
/** |
375 |
* Informs all registered {@link PropertyChangeListener}s about a change of |
* Informs all registered {@link PropertyChangeListener}s about a change of |
376 |
* the the {@link Locale}. |
* type LOCALE_CHANGE_PROPERTY the the {@link Locale}. |
377 |
*/ |
*/ |
378 |
public static void fireLocaleChangeEvents() { |
public static void fireLocaleChangeEvents() { |
379 |
PropertyChangeEvent pce = new PropertyChangeEvent(new Translation( |
PropertyChangeEvent pce = new PropertyChangeEvent(new Translation( |
380 |
new ArrayList<String>(), "fakeSource"), LOCALECHANGE_PROPERTY, |
new ArrayList<String>(), "fakeSource"), LOCALE_CHANGE_PROPERTY, |
381 |
null, getActiveLang()); |
null, getActiveLang()); |
382 |
for (PropertyChangeListener pcl : listenersLocaleChange) { |
for (PropertyChangeListener pcl : listenersLocaleChange) { |
383 |
if (pcl != null) |
if (pcl != null) |
387 |
|
|
388 |
/** |
/** |
389 |
* Informs all registered {@link PropertyChangeListener}s about a change of |
* Informs all registered {@link PropertyChangeListener}s about a change of |
390 |
* the the {@link Locale}. |
* type ACTIVELANG_CHANGE_PROPERTY the the {@link Locale}. |
391 |
*/ |
*/ |
392 |
public static void fireActiveLangChangeEvents() { |
public static void fireActiveLangChangeEvents() { |
393 |
PropertyChangeEvent pce = new PropertyChangeEvent(new Translation( |
PropertyChangeEvent pce = new PropertyChangeEvent(new Translation( |
394 |
new ArrayList<String>(), "fakeSource"), |
new ArrayList<String>(), "fakeSource"), |
395 |
ACTIVELANG_CHANGE_PROPERTY, null, getActiveLang()); |
ACTIVELANG_CHANGE_PROPERTY, null, getActiveLang()); |
396 |
for (PropertyChangeListener pcl : listenersActiveLangChange) { |
for (PropertyChangeListener pcl : listenersLocaleChange) { |
397 |
if (pcl != null) |
if (pcl != null) |
398 |
pcl.propertyChange(pce); |
pcl.propertyChange(pce); |
399 |
} |
} |
520 |
public String toString(String lang) { |
public String toString(String lang) { |
521 |
return get(lang); |
return get(lang); |
522 |
} |
} |
523 |
|
|
524 |
|
/** |
525 |
|
* Will set the default Locale (if not already equal) and fire Locale change |
526 |
|
* events. |
527 |
|
* |
528 |
|
* @param if <code>null</code> will do nothing. |
529 |
|
*/ |
530 |
|
public static void setDefaultLocale(Locale locale) { |
531 |
|
|
532 |
|
if (locale == null) |
533 |
|
return; |
534 |
|
|
535 |
|
if (Locale.getDefault().equals(locale)) |
536 |
|
return; |
537 |
|
Locale.setDefault(locale); |
538 |
|
/** |
539 |
|
* Setting default locale for Swing JComponents to work around bug |
540 |
|
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4884480 |
541 |
|
*/ |
542 |
|
JComponent.setDefaultLocale(locale); |
543 |
|
|
544 |
|
fireLocaleChangeEvents(); |
545 |
|
} |
546 |
|
|
547 |
} |
} |