diff --git a/v2/i18n/localizer.go b/v2/i18n/localizer.go index 256cd494..9895fcbd 100644 --- a/v2/i18n/localizer.go +++ b/v2/i18n/localizer.go @@ -190,7 +190,11 @@ func (l *Localizer) getMessageTemplate(id string, defaultMessage *Message) (lang if defaultMessage == nil { return language.Und, nil, &MessageNotFoundErr{tag: tag, messageID: id} } - return tag, NewMessageTemplate(defaultMessage), nil + mt := NewMessageTemplate(defaultMessage) + if mt == nil { + return language.Und, nil, &MessageNotFoundErr{tag: tag, messageID: id} + } + return tag, mt, nil } // Fallback to default language in bundle. diff --git a/v2/i18n/localizer_test.go b/v2/i18n/localizer_test.go index 3dedfb67..c13fe7bd 100644 --- a/v2/i18n/localizer_test.go +++ b/v2/i18n/localizer_test.go @@ -577,6 +577,15 @@ func localizerTests() []localizerTest { }, expectedErr: &MessageNotFoundErr{tag: language.AmericanEnglish, messageID: "Hello"}, }, + { + name: "empty default message", + defaultLanguage: language.English, + acceptLangs: []string{"en"}, + conf: &LocalizeConfig{ + DefaultMessage: &Message{}, + }, + expectedErr: &MessageNotFoundErr{tag: language.English, messageID: ""}, + }, } }