Allow to suppress the warning message about unknown messages from translation layer

This commit is contained in:
Grahame Grieve 2020-06-24 15:06:27 +10:00
parent 7ac714c2b6
commit c2c10872e1
1 changed files with 15 additions and 2 deletions

View File

@ -14,6 +14,7 @@ public abstract class I18nBase {
private Locale locale; private Locale locale;
private ResourceBundle i18nMessages; private ResourceBundle i18nMessages;
private boolean warnAboutMissingMessages = false;
public Locale getLocale() { public Locale getLocale() {
if (Objects.nonNull(locale)) { if (Objects.nonNull(locale)) {
@ -47,9 +48,11 @@ public abstract class I18nBase {
private boolean messageExistsForLocale(String message) { private boolean messageExistsForLocale(String message) {
checkResourceBundleIsLoaded(); checkResourceBundleIsLoaded();
if (!i18nMessages.containsKey(message)) { if (!i18nMessages.containsKey(message)) {
if (warnAboutMissingMessages ) {
System.out.println("Attempting to localize message " + message + ", but no such equivalent message exists for" + System.out.println("Attempting to localize message " + message + ", but no such equivalent message exists for" +
" the local " + getLocale()); " the local " + getLocale());
} }
}
return i18nMessages.containsKey(message); return i18nMessages.containsKey(message);
} }
@ -78,4 +81,14 @@ public abstract class I18nBase {
public void setValidationMessageLanguage(Locale locale) { public void setValidationMessageLanguage(Locale locale) {
i18nMessages = ResourceBundle.getBundle("Messages", locale); i18nMessages = ResourceBundle.getBundle("Messages", locale);
} }
public boolean isWarnAboutMissingMessages() {
return warnAboutMissingMessages;
}
public void setWarnAboutMissingMessages(boolean warnAboutMissingMessages) {
this.warnAboutMissingMessages = warnAboutMissingMessages;
}
} }