[Schmitzm-commits] r905 - trunk/src/skrueger/i8n
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jun 10 10:00:38 CEST 2010
Author: alfonx
Date: 2010-06-10 10:00:37 +0200 (Thu, 10 Jun 2010)
New Revision: 905
Modified:
trunk/src/skrueger/i8n/Translation.java
Log:
Added new method setBestMatchingLanguage to Translations
Modified: trunk/src/skrueger/i8n/Translation.java
===================================================================
--- trunk/src/skrueger/i8n/Translation.java 2010-06-10 07:59:38 UTC (rev 904)
+++ trunk/src/skrueger/i8n/Translation.java 2010-06-10 08:00:37 UTC (rev 905)
@@ -40,6 +40,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Random;
+import java.util.Set;
import java.util.WeakHashMap;
import javax.swing.JComponent;
@@ -48,6 +49,8 @@
import org.geotools.util.WeakHashSet;
import org.opengis.util.InternationalString;
+import schmitzm.lang.ResourceProvider;
+import schmitzm.lang.SortableVector;
import skrueger.geotools.Copyable;
/**
@@ -60,9 +63,9 @@
public class Translation extends HashMap<String, String> implements
Copyable<Translation>, Serializable {
-
+
private static final long serialVersionUID = -347702744122305245L;
-
+
public static final String LOCALECHANGE_PROPERTY = "localechange";
public static final String NO_TRANSLATION = "NO TRANSLATION";
public static final String DEFAULT_KEY = "default";
@@ -81,8 +84,6 @@
Locale locale = Locale.getDefault();
setActiveLang(locale.getLanguage());
}
-
-
private WeakHashSet<ActionListener> actionListeners = new WeakHashSet<ActionListener>(
ActionListener.class);
@@ -107,7 +108,7 @@
/**
* Set up the {@link Translation}-system to use language. If a change is
* performed, events are fired to listeners. Nothing is done if the new
- * language equals the old language. The system's default locale is changed.
+ * language equals the old language. The system's default {@link Locale} is changed.
*
* @param newLang
* The ISO Code of the new active language
@@ -184,9 +185,9 @@
put(DEFAULT_KEY, defaultTranslation);
} else
for (String code : languages) {
-// if (code.equals(getActiveLang())) {
- put(code, defaultTranslation);
-// }
+ // if (code.equals(getActiveLang())) {
+ put(code, defaultTranslation);
+ // }
}
}
@@ -341,8 +342,8 @@
*/
public void addTranslationChangeListener(ActionListener actionListener) {
if (actionListeners.add(actionListener)) {
-// LOGGER
-// .debug("registering a new translationChangeActionListener in the WeakHashSet");
+ // LOGGER
+ // .debug("registering a new translationChangeActionListener in the WeakHashSet");
}
}
@@ -422,4 +423,33 @@
return true;
}
+ /**
+ * Goes through the available languages of the FIRST registered {@link ResourceProvider} and set the active locale to the fist match.
+ *
+ * @param fireChangeEvent if <code>true</code>, a Translation.fireLocaleChangeEvents() is issued.
+
+ * @return
+ */
+ public static boolean setFirstmatchingLanguage(List<String> languages,
+ boolean fireChangeEvent) {
+
+ SortableVector<ResourceProvider> registeredResourceProvider = ResourceProvider
+ .getRegisteredResourceProvider();
+ Set<Locale> available = ResourceProvider.getAvailableLocales(
+ registeredResourceProvider.get(0), true);
+
+ for (String l : languages) {
+ for (Locale loc : available) {
+ if (loc.getLanguage().equals(l)) {
+ Translation.setActiveLang(l);
+ if (fireChangeEvent)
+ Translation.fireLocaleChangeEvents();
+ return true;
+ }
+ }
+ }
+
+ return false;
+
+ }
}
More information about the Schmitzm-commits
mailing list