Is there any limitation when using Import?
adiatma85 opened this issue · 0 comments
adiatma85 commented
Hello,
Go version: 1.20
Universal Translator version: v0.18.0
I would like to asking if there are any limitation when importing translation using JSON format.
In before, when using this library, I always got the translation I meant. But in couple of days, when I add new key in JSON format, the translator return "unknown translation"
Here is the snippet of my code:
import (
"github.com/go-playground/locales"
"github.com/go-playground/locales/en"
"github.com/go-playground/locales/id"
ut "github.com/go-playground/universal-translator"
)
func InitTranslator() *ut.UniversalTranslator{
enLocales := en.New()
idLocales := id.New()
supportedLocales := []locales.Translator{
enLocales, idLocales,
}
newTranslator := ut.New(enLocales, supportedLocales...)
newTranslator.Import(ut.FormatJSON, fmt.Sprintf("%s/%s", pwd, "translation"))
if err = newTranslator.VerifyTranslations(); err != nil {
log.Fatal(context.Background(), err)
}
}
Here is my translation file:
// ... there already a lot of key and value above these two
{
"key": "morning",
"locales": "en",
"trans": "Morning"
},
{
"key": "morning",
"locales": "id",
"trans": "Pagi"
},
But when I call with:
trans, found := newTranslator.GetTranslator("id")
if !found {
log.Fatal("not found translation")
}
return trans.T("morning")
It will return: Unknown Translation
. So, how do I fix it?