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

Is there any limitation when using Import? #34

Open
adiatma85 opened this issue Jun 18, 2023 · 0 comments
Open

Is there any limitation when using Import? #34

adiatma85 opened this issue Jun 18, 2023 · 0 comments

Comments

@adiatma85
Copy link

adiatma85 commented Jun 18, 2023

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?

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

1 participant