Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes nil reference exception if localization text is empty, fixes #207 #208

Merged
merged 5 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions v2/goi18n/merge_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
nicksnyder marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
32 changes: 32 additions & 0 deletions v2/goi18n/merge_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ func TestMerge(t *testing.T) {
"active.en-US.toml": []byte("1HelloMessage = \"Hello\"\n"),
},
},
{
MJacred marked this conversation as resolved.
Show resolved Hide resolved
name: "single identity, one localization text missing",
sourceLanguage: language.AmericanEnglish,
inFiles: map[string][]byte{
"one.en-US.toml": []byte(`
1HelloMessage = ""
Body = "Finally some text!"
`),
},
outFiles: map[string][]byte{
"active.en-US.toml": []byte(`Body = "Finally some text!"
`),
},
},
{
name: "plural identity",
sourceLanguage: language.AmericanEnglish,
Expand All @@ -52,6 +66,24 @@ other = "{{.Count}} unread emails"
description = "Message that tells the user how many unread emails they have"
one = "{{.Count}} unread email"
other = "{{.Count}} unread emails"
`),
},
},
{
name: "plural identity, missing localization text",
sourceLanguage: language.AmericanEnglish,
inFiles: map[string][]byte{
"active.en-US.toml": []byte(`
Body = "Some text!"

[MissingTranslation]
description = "I wonder what it was?!"
one = ""
other = ""
`),
},
outFiles: map[string][]byte{
"active.en-US.toml": expectFile(`Body = "Some text!"
`),
},
},
Expand Down