fix: 🐛 Fix fallbacking of locale to the code to prevent errors

pull/1580/head
Dominik Frantisek Bucik 2021-12-02 16:22:03 +01:00
parent 2553b0e5f8
commit ceb01c78e7
No known key found for this signature in database
GPG Key ID: 25014C8DB2E7E62D
2 changed files with 5 additions and 2 deletions

View File

@ -58,6 +58,8 @@ public class JsonMessageSource extends AbstractMessageSource {
this.config = config; this.config = config;
} }
@Override @Override
protected MessageFormat resolveCode(String code, Locale locale) { protected MessageFormat resolveCode(String code, Locale locale) {
@ -73,7 +75,7 @@ public class JsonMessageSource extends AbstractMessageSource {
if (value == null) { if (value == null) {
// if it's still null, return null // if it's still null, return null
return null; return new MessageFormat(code, locale);
} else { } else {
// otherwise format the message // otherwise format the message
return new MessageFormat(value, locale); return new MessageFormat(value, locale);

View File

@ -43,7 +43,8 @@ public class TestJsonMessageSource {
@Test @Test
public void verifyWhenLocaleDoesNotExist_cannotResolveCode() { public void verifyWhenLocaleDoesNotExist_cannotResolveCode() {
String code = "test";
MessageFormat mf = jsonMessageSource.resolveCode("test", localeThatDoesNotHaveAFile); MessageFormat mf = jsonMessageSource.resolveCode("test", localeThatDoesNotHaveAFile);
assertNull(mf); assertEquals(code, mf.toPattern());
} }
} }