gobuffalo i18n translator is accessible in actions but how can I access it on my models? It requires the buffalo.Context
as a param in T *i18n.Translator
.
Thank you in advance!
gobuffalo i18n translator is accessible in actions but how can I access it on my models? It requires the buffalo.Context
as a param in T *i18n.Translator
.
Thank you in advance!
This is a workaround solution.
1.In models.go create the following function
import "github.com/nicksnyder/go-i18n/i18n"
var Lang = "en"
func t(translationID string, args ...interface{}) string{
T, _ := i18n.Tfunc(Lang, fmt.Sprintf("locales/models.%s.yaml", Lang))
return T(translationID,args... )
}
In your init() function add
i18n.LoadTranslationFile(fmt.Sprintf("locales/models.fr.yaml"))
i18n.LoadTranslationFile(fmt.Sprintf("locales/models.en.yaml"))
... other locale files if needed....
In your models you can now use the translate function t("translationID")
You can change the models locale by simple setting the Lang variable models.Lang="fr"