From 7acc653f1982f2f839aadfe49f4277b160c94390 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:21:33 +0000 Subject: Only use configured locales git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@279 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../src/main/java/at/asit/pdfover/gui/Constants.java | 2 +- .../src/main/java/at/asit/pdfover/gui/Messages.java | 17 ++++++++++++++++- .../asit/pdfover/gui/workflow/ConfigProviderImpl.java | 8 ++++---- 3 files changed, 21 insertions(+), 6 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java index e570a773..3879e79e 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java @@ -29,7 +29,7 @@ public class Constants { private static Display display = Display.getCurrent(); /** Supported locales */ - public static final Locale[] SUPPORTED_LOCALES = { Locale.ENGLISH, Locale.GERMAN }; + public static final Locale[] SUPPORTED_LOCALES = { Locale.GERMAN, Locale.ENGLISH }; /** Main window height */ public static final int MAINWINDOW_HEIGHT = 780; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java index 77e2f764..b17e168a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Messages.java @@ -41,11 +41,24 @@ public class Messages { //private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle // .getBundle(BUNDLE_NAME); - private static Locale currentLocale = Locale.getDefault(); + private static Locale currentLocale = getDefaultLocale(); private Messages() { } + /** + * Get the closest match to the system default Locale out of the supported locales + * @return the default locale + */ + public static Locale getDefaultLocale() { + Locale ld = Locale.getDefault(); + for (Locale l : Constants.SUPPORTED_LOCALES) { + if (l.equals(ld) || l.getLanguage().equals(ld.getLanguage())) + return l; + } + return Constants.SUPPORTED_LOCALES[0]; + } + /** * Sets the currently used locals * @param locale @@ -56,9 +69,11 @@ public class Messages { private static ResourceBundle getBundle(Locale locale) { if(!bundles.containsKey(locale)) { + log.debug("Loading resource bundle for " + locale); //$NON-NLS-1$ ResourceBundle tmp = null; try { tmp = ResourceBundle.getBundle(BUNDLE_NAME, locale); + log.debug("Received bundle for " + tmp.getLocale()); //$NON-NLS-1$ } catch(Exception e) { log.error("NO RESOURCE BUNDLE FOR " + locale.toString(), e); //$NON-NLS-1$ tmp = ResourceBundle.getBundle(BUNDLE_NAME); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java index 1e628342..ee44dad2 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java @@ -66,8 +66,8 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { private String defaultPassword = STRING_EMPTY; - private Locale locale = Locale.getDefault(); - private Locale signLocale = Locale.getDefault(); + private Locale locale = Messages.getDefaultLocale(); + private Locale signLocale = this.locale; private String emblem = STRING_EMPTY; @@ -593,7 +593,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { @Override public void setLocale(Locale locale) { if(locale == null) { - this.locale = Locale.getDefault(); + this.locale = Messages.getDefaultLocale(); } else { this.locale = locale; Locale.setDefault(locale); @@ -607,7 +607,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { @Override public void setSignLocale(Locale locale) { if(locale == null) { - this.signLocale = Locale.getDefault(); + this.signLocale = Messages.getDefaultLocale(); } else { this.signLocale = locale; } -- cgit v1.2.3