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

read translations from string? #18

Closed
cytec opened this issue Feb 16, 2015 · 4 comments
Closed

read translations from string? #18

cytec opened this issue Feb 16, 2015 · 4 comments

Comments

@cytec
Copy link

cytec commented Feb 16, 2015

I would love to include my translated files with go-bindata thus not providing access to a file but a string/byte pointer of the file content.

Is there a way i can load translations from string or an go-bindata Asset?
see: https://github.com/jteeuwen/go-bindata

@nicksnyder
Copy link
Owner

Can you describe why you want to do this and/or the advantages of using go-bindata over the current approach of loading a JSON file at runtime?

@cytec
Copy link
Author

cytec commented Feb 17, 2015

because i think its simpler to distribute a single binary to the enduser then needing them to have a setup folder structure with JSON Files.

i'm currently useing a "workaround" like this:

transString, _ := Asset("translations/de-DE.all.json")
var transUnmarshal []map[string]interface{}
err := json.Unmarshal(transString, &transUnmarshal)
if err != nil {
    fmt.Println(err)
}
lang := language.MustParse("de-DE")
for _, str := range transUnmarshal {
    trans, _ := translation.NewTranslation(str)
    i18n.AddTranslation(lang[0], trans)
}

@nicksnyder
Copy link
Owner

I added ParseTranslationFileBytes, which should give you what you want. Reopen if that doesn't work for you.

@cytec
Copy link
Author

cytec commented Feb 18, 2015

works perfectly, thanks :)

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