From 5cd78f58a9730dc4855f445deb2d1b77800466cb Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 2 Jul 2017 12:01:05 +0200 Subject: [PATCH] Resource Fallback auf unqualifizierte Resourcen-IDs --- web/src/main/java/de/hsadmin/web/I18N.java | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/web/src/main/java/de/hsadmin/web/I18N.java b/web/src/main/java/de/hsadmin/web/I18N.java index df14604..4aadac6 100644 --- a/web/src/main/java/de/hsadmin/web/I18N.java +++ b/web/src/main/java/de/hsadmin/web/I18N.java @@ -7,14 +7,29 @@ public class I18N { private static final ResourceBundle TEXTS = ResourceBundle.getBundle("de.hsadmin.web.main"); - public static String getText(final String textProperty) { - String textValue; - try{ - textValue = I18N.TEXTS.getString(textProperty); - }catch(MissingResourceException e){ - textValue = "./. " + textProperty; + /** + * Loads a String resource from the *.properties files. + * + * @param optionallyQualifiedTextProperty + * ID of the resource, optionally qualified module the module name, + * e.g. "customer.name" (preferred) or simply "name" (legacy). + * @return the String resource, e.g. a label or message, usually to be displayed to the user + */ + public static String getText(final String optionallyQualifiedTextProperty) { + String textValue = getTextImpl(optionallyQualifiedTextProperty); + return textValue != null ? textValue : "./. " + optionallyQualifiedTextProperty; + } + + public static String getTextImpl(final String optionallyQualifiedTextProperty) { + try { + return I18N.TEXTS.getString(optionallyQualifiedTextProperty); + } catch(MissingResourceException e1) { + String[] parts = optionallyQualifiedTextProperty.split(".", 2); + if ( parts.length > 1 ) { + return getTextImpl(parts[1]); + } } - return textValue; + return null; } }