Resource Fallback auf unqualifizierte Resourcen-IDs

This commit is contained in:
Michael Hoennig 2017-07-02 12:01:05 +02:00
parent 92c50c8e48
commit 5cd78f58a9

View File

@ -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;
}
}