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

goi18n merge resulted in "invalid memory address or nil pointer dereference" #235

Open
nuoyan opened this issue Oct 27, 2020 · 1 comment

Comments

@nuoyan
Copy link

nuoyan commented Oct 27, 2020

On Mac. Installed goi18n command following the README.
go version go1.14.6 darwin/amd64

Steps to reproduce:

  1. follow the steps in README to extract messages, translate, and load new langauge's file into bundle. Verify the new language worked. I could reproduce this using the code from the example for this exercise.

  2. Add a new message. In my case, I added:

	newMsg := localizer.MustLocalize(&i18n.LocalizeConfig{
		DefaultMessage: &i18n.Message{
			ID:          "NewMsg",
			Description: "A new message",
			One:         "This is a new message",
		},
		PluralCount: 0,
	})
  1. Follow Translating new messages.

After go extract, I verified the EN message file had the new message. At this moment, my EN and ES message files look like the following:

active.en.toml:

HelloPerson = "Hello {{.Name}}"

[MyUnreadEmails]
description = "The number of unread emails I have"
one = "I have {{.PluralCount}} unread email."
other = "I have {{.PluralCount}} unread emails."

[PersonUnreadEmails]
description = "The number of unread emails a person has"
one = "{{.Name}} has {{.UnreadEmailCount}} unread email."
other = "{{.Name}} has {{.UnreadEmailCount}} unread emails."

[NewMsg]
description = "A new message"
one = "This is a new message"

active.es.toml:

[HelloPerson]
hash = "sha1-5b49bfdad81fedaeefb224b0ffc2acc58b09cff5"
other = "Hola {{.Name}}"

[MyUnreadEmails]
description = "The number of unread emails I have"
hash = "sha1-6a65d17f53981a3657db1897630e9cb069053ea8"
one = "Tengo {{.PluralCount}} correo electrónico sin leer"
other = "Tengo {{.PluralCount}} correos electrónicos no leídos"

[PersonUnreadEmails]
description = "The number of unread emails a person has"
hash = "sha1-3a672fa89c5c8564bb233c907638004983792464"
one = "{{.Name}} tiene {{.UnreadEmailCount}} correo electrónico no leído"
other = "{{.Name}} tiene {{.UnreadEmailCount}} correos electrónicos no leídos"

Now run goi18n merge active.*.toml.

Got:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11e250d]

goroutine 1 [running]:
main.hash(0xc00008ea00, 0xc000090750, 0xc0000f018c)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/merge_command.go:297 +0x12d
main.merge(0xc0000ddc98, 0x860086, 0x0, 0x0, 0x124e954, 0x1, 0x124ef7c, 0x4, 0x203000, 0x203000, ...)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/merge_command.go:139 +0x602
main.(*mergeCommand).execute(0xc0000b81e0, 0xc0000b2060, 0x2)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/merge_command.go:92 +0x234
main.testableMain(0xc0000b2050, 0x3, 0x3, 0xc00008c058)
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/main.go:123 +0x3e2
main.main()
	/Users/foo/go/src/github.com/kouzoh/go-i18n/v2/goi18n/main.go:96 +0x64
@D-PorcoRosso
Copy link

I have run into this issue too, I think your
[NewMsg]
description = "A new message"
one = "This is a new message"

Missing "other" key, this "other" will be used in _, _ = io.WriteString(h, t.PluralTemplates[plural.Other].Src)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants