Better error message when localizer can't find key
This commit is contained in:
parent
cc6c32f987
commit
0e7405cef2
|
@ -34,7 +34,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
*/
|
*/
|
||||||
public class HapiLocalizer {
|
public class HapiLocalizer {
|
||||||
|
|
||||||
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(HapiLocalizer.class);
|
||||||
private List<ResourceBundle> myBundle = new ArrayList<ResourceBundle>();
|
private List<ResourceBundle> myBundle = new ArrayList<ResourceBundle>();
|
||||||
|
|
||||||
private final Map<String, MessageFormat> myKeyToMessageFormat = new ConcurrentHashMap<String, MessageFormat>();
|
private final Map<String, MessageFormat> myKeyToMessageFormat = new ConcurrentHashMap<String, MessageFormat>();
|
||||||
|
|
||||||
public HapiLocalizer() {
|
public HapiLocalizer() {
|
||||||
|
@ -47,6 +49,24 @@ public class HapiLocalizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String findFormatString(String theQualifiedKey) {
|
||||||
|
String formatString = null;
|
||||||
|
for (ResourceBundle nextBundle : myBundle) {
|
||||||
|
if (nextBundle.containsKey(theQualifiedKey)) {
|
||||||
|
formatString = nextBundle.getString(theQualifiedKey);
|
||||||
|
}
|
||||||
|
if (isNotBlank(formatString)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formatString == null) {
|
||||||
|
ourLog.warn("Unknown localization key: {}", theQualifiedKey);
|
||||||
|
formatString = "!MESSAGE!";
|
||||||
|
}
|
||||||
|
return formatString;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMessage(Class<?> theType, String theKey, Object... theParameters) {
|
public String getMessage(Class<?> theType, String theKey, Object... theParameters) {
|
||||||
return getMessage(theType.getName() + '.' + theKey, theParameters);
|
return getMessage(theType.getName() + '.' + theKey, theParameters);
|
||||||
}
|
}
|
||||||
|
@ -68,22 +88,4 @@ public class HapiLocalizer {
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findFormatString(String theQualifiedKey) {
|
|
||||||
String formatString = null;
|
|
||||||
for (ResourceBundle nextBundle : myBundle) {
|
|
||||||
if (nextBundle.containsKey(theQualifiedKey)) {
|
|
||||||
formatString = nextBundle.getString(theQualifiedKey);
|
|
||||||
}
|
|
||||||
if (isNotBlank(formatString)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formatString == null) {
|
|
||||||
formatString = "!MESSAGE!";
|
|
||||||
}
|
|
||||||
return formatString;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue