Better error message when localizer can't find key

This commit is contained in:
James 2016-08-22 21:33:07 -04:00
parent cc6c32f987
commit 0e7405cef2
1 changed files with 20 additions and 18 deletions

View File

@ -34,7 +34,9 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class HapiLocalizer {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(HapiLocalizer.class);
private List<ResourceBundle> myBundle = new ArrayList<ResourceBundle>();
private final Map<String, MessageFormat> myKeyToMessageFormat = new ConcurrentHashMap<String, MessageFormat>();
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) {
return getMessage(theType.getName() + '.' + theKey, theParameters);
}
@ -68,22 +88,4 @@ public class HapiLocalizer {
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;
}
}