Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/go-i18n.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMJacred <loesch.benny92@gmx.de>2020-09-29 02:40:16 +0300
committerGitHub <noreply@github.com>2020-09-29 02:40:16 +0300
commit8f09be85f761f8869081b9b7c7887b46e3b5da21 (patch)
treeb77bf405353657b524b078b2c978a1a0beec9201
parent354b2fc20611e59aaf6e988cf324a1d85caa2917 (diff)
fixes nil reference exception if localization text is empty, fixes #207 (#208)
-rw-r--r--v2/goi18n/merge_command.go8
-rw-r--r--v2/goi18n/merge_command_test.go32
2 files changed, 38 insertions, 2 deletions
diff --git a/v2/goi18n/merge_command.go b/v2/goi18n/merge_command.go
index 9765c6d..b736dfe 100644
--- a/v2/goi18n/merge_command.go
+++ b/v2/goi18n/merge_command.go
@@ -125,12 +125,16 @@ 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 {
+ 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
diff --git a/v2/goi18n/merge_command_test.go b/v2/goi18n/merge_command_test.go
index ff7c221..ea6e2ca 100644
--- a/v2/goi18n/merge_command_test.go
+++ b/v2/goi18n/merge_command_test.go
@@ -36,6 +36,20 @@ func TestMerge(t *testing.T) {
},
},
{
+ 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,
inFiles: map[string][]byte{
@@ -56,6 +70,24 @@ 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!"
+`),
+ },
+ },
+ {
name: "migrate source lang from v1 format",
sourceLanguage: language.AmericanEnglish,
inFiles: map[string][]byte{