From 71f6d8d015aa364f5ceaa18f40ee78d8ff776cae Mon Sep 17 00:00:00 2001 From: MJacred Date: Thu, 9 Jan 2020 12:44:10 +0100 Subject: [PATCH] prevent nil exception on empty localization text fixes #207 --- v2/goi18n/merge_command.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/v2/goi18n/merge_command.go b/v2/goi18n/merge_command.go index 9765c6d3..cc66a21e 100644 --- a/v2/goi18n/merge_command.go +++ b/v2/goi18n/merge_command.go @@ -125,12 +125,17 @@ func merge(messageFiles map[string][]byte, sourceLanguageTag language.Tag, outdi } templates := map[string]*i18n.MessageTemplate{} for _, m := range mf.Messages { - templates[m.ID] = i18n.NewMessageTemplate(m) + template := i18n.NewMessageTemplate(m) + if template == nil { + fmt.Fprintf(os.Stderr, "missing translation for message id %q\n", m.ID) + continue + } + templates[m.ID] = template } if mf.Tag == sourceLanguageTag { for _, template := range templates { if sourceMessageTemplates[template.ID] != nil { - return nil, fmt.Errorf("multiple source translations for id %s", template.ID) + return nil, fmt.Errorf("multiple source translations for id %q", template.ID) } template.Hash = hash(template) sourceMessageTemplates[template.ID] = template