fix: 🐛 Fix fallbacking of locale to the code to prevent errors
parent
2553b0e5f8
commit
ceb01c78e7
|
@ -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);
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue