-
Notifications
You must be signed in to change notification settings - Fork 266
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
panic: Only a pointer to struct can be unmarshaled from TOML #95
Comments
Just tagged 2.0.0.beta.1 so there may be some bugs. I will take a look |
Hi,
Did you upload a change?
The MustLocalize example on:
https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n#pkg-examples <https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n#pkg-examples>
fails.
Also, my toml file is generated by extract, so I assume it’s fine.
the error is happening because the go-toml code does not like the var raw interface{} as struct def’n
this code is parse.go::ParseMessageFileBytes()
THANK YOU SO MUCH FOR THE RAPID RESPONSE.
I’m an expert programmer with 30+ years, but a relative newcomer to go, so I’m not as helpful as I could be :{
Dean
On Apr 17, 2018, at 8:51 AM, Nick Snyder <notifications@github.com> wrote:
Closed #95 <#95> via #96 <#96>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#95 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AFF8o1vXGDsFjCusYItOBIur54rdOJ1Bks5tpg90gaJpZM4TXQXH>.
|
You probably need to If you are still having issues, please post what your toml file looks like. |
I’m pulling all the v2 stuff, as that’s what my code requires.
#! /bin/bash
pushd $(cd -P -- "$(dirname -- "$0")" && pwd -P)
export GOPATH=`pwd`
go get -u github.com/nicksnyder/go-i18n/v2/goi18n
go get -u github.com/urfave/cli
go get -u golang.org/x/text/language
go get -u github.com/nicksnyder/go-i18n/v2/i18n
go get -u github.com/pelletier/go-toml
source build.cmd
Your code example that fails:
bundle := i18n.NewBundle(language.English)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
bundle.MustParseMessageFileBytes([]byte(`
HelloWorld = "Hello World!"
`), "en.toml")
bundle.MustParseMessageFileBytes([]byte(`
HelloWorld = "Hola Mundo!"
`), "es.toml")
{
localizer := i18n.NewLocalizer(bundle, "en-US")
fmt.Println(localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "HelloWorld"}))
}
{
localizer := i18n.NewLocalizer(bundle, "es-ES")
fmt.Println(localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: "HelloWorld"}))
}
So far, I’m using none of my own code.
I recommend you forget about my code and debug your example on:
The MustLocalize example on:
https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n#pkg-examples <https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n#pkg-examples>
My code is this:
bundle := i18n.NewBundle(language.English)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
bundle.MustLoadMessageFile(path.Dir(os.Args[0]) + "/i18n/active.fr.toml")
The toml file is:
[DownloadHelp]
hash = "sha1-b8545b47f150949c26d19c9eb7fc55e855de432a"
other = "télécharger paquet d'apm"
[HelloPerson]
hash = "sha1-5b49bfdad81fedaeefb224b0ffc2acc58b09cff5"
other = "Bonjour {{.Name}}"
Thank you
On Apr 17, 2018, at 10:56 AM, Nick Snyder <notifications@github.com> wrote:
You probably need to go get -u github.com/nicksnyder/go-i18n. If you are using a dependency manager then you will probably need to update the version it points to (although I haven't tagged a new release so you would need to reference by commit hash).
If you are still having issues, please post what your toml file looks like.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#95 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AFF8o-c8-2vguTZOcQQ2mDp-HzIWIIwaks5tpizCgaJpZM4TXQXH>.
|
Examples are automatically run and verified as part of unit tests (https://github.com/nicksnyder/go-i18n/blob/master/v2/i18n/example_test.go), so there must be a difference between the example code and what you are actually running if it is failing for you. |
got it.
You are using a different toml package than me.
Not sure how it slipped into my code.
now using:
"github.com/BurntSushi/toml”
instead of:
github.com/pelletier/go-toml
Thank you!
Seems to work now.
On Apr 17, 2018, at 1:22 PM, Nick Snyder <notifications@github.com> wrote:
Examples are automatically run and verified as part of unit tests (https://github.com/nicksnyder/go-i18n/blob/master/v2/i18n/example_test.go), so there must be a difference between the example code and what you are actually running if it is failing for you.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Glad you were able to figure it out. Versioning dependencies (and declaring which dependencies a package depends on) is an active area of development in the Go community. You may be interested to read this: https://research.swtch.com/vgo-intro |
I'm a newb to this project, and I think I'm following the instructions, but perhaps I'm missing something?
This code generates the error in the subject line:
bundle := i18n.NewBundle(language.English) bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal) bundle.MustLoadMessageFile(path.Dir(os.Args[0]) + "/i18n/active.fr.toml")
The toml file originates from a goi18n extract.
In addition, the
MustLocalize
example on this page generates the same error:https://godoc.org/github.com/nicksnyder/go-i18n/v2/i18n#pkg-examples
Thank you in advance.
The text was updated successfully, but these errors were encountered: