Skip to content

Commit

Permalink
fix(i18n): change languageinforef to ptr (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Apr 24, 2023
1 parent c6cdec1 commit a66f3f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion i18n/translator-factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type multiTranslatorFactory struct {
func (f *multiTranslatorFactory) New(lang *LanguageInfo) Translator {
f.setup(lang)

liRef := utils.NewRoProp(*lang)
liRef := utils.NewRoProp(lang)
multi := &multiContainer{
localizers: make(localizerContainer),
}
Expand Down
6 changes: 3 additions & 3 deletions i18n/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type Translator interface {
Localise(data Localisable) string
LanguageInfoRef() utils.RoProp[LanguageInfo]
LanguageInfoRef() utils.RoProp[*LanguageInfo]
negotiate(other Translator) Translator
}

Expand Down Expand Up @@ -146,10 +146,10 @@ func Text(data Localisable) string {
// Text function
type i18nTranslator struct {
mx localizerMultiplexor
languageInfoRef utils.RoProp[LanguageInfo]
languageInfoRef utils.RoProp[*LanguageInfo]
}

func (t *i18nTranslator) LanguageInfoRef() utils.RoProp[LanguageInfo] {
func (t *i18nTranslator) LanguageInfoRef() utils.RoProp[*LanguageInfo] {
return t.languageInfoRef
}

Expand Down
23 changes: 23 additions & 0 deletions i18n/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ var _ = Describe("Translator", Ordered, func() {
})
})

Context("AppendSources", func() {
Context("given: Translator exists", func() {
It("🧪 should: be able to add source", func() {
if err := xi18n.Use(func(o *xi18n.UseOptions) {
o.Tag = language.AmericanEnglish
o.From.Path = l10nPath
o.From.Sources = testTranslationFile
}); err != nil {
Fail(err.Error())
}

additional := make(xi18n.TranslationFiles)
additional[GrafficoSourceID] = xi18n.TranslationSource{
Name: "test.graffico",
}

xi18n.TxRef.Get().LanguageInfoRef().Get().From.AppendSources(&additional)
_, found := xi18n.TxRef.Get().LanguageInfoRef().Get().From.Sources[GrafficoSourceID]
Expect(found).To(BeTrue())
})
})
})

Context("Use", func() {
When("requested language is available", func() {
It("🧪 should: create Translator", func() {
Expand Down

0 comments on commit a66f3f9

Please sign in to comment.