Skip to content

Add Translate and TranslatePlurals methods

Latest
Compare
Choose a tag to compare
@arthurkushman arthurkushman released this 24 Aug 10:27
· 6 commits to main since this release
// Translate translates message by key and language, replacing with params from custom struct
// there should be templated message in db (for particular language) to perform such transformation ex.:
// Hello {{.Name}}, it's {{.Time}}.
// Basket: {{.Product}} price is {{.Price}}.
func (i *Intl) Translate(key, lang string, params any) (string, error)

// TranslatePlurals translates any message with plurals based on LocalizeConfig object
// see: github.com/nicksnyder/go-i18n/v2/i18n
// it tries to find translation language and makes fallback if not found
/*
ex. of LocalizeConfig:
localizer.Localize(&i18n.LocalizeConfig{
    DefaultMessage: &i18n.Message{
        ID: "PersonCats",
        One: "{{.Name}} has {{.Count}} cat.",
        Other: "{{.Name}} has {{.Count}} cats.",
    },
    TemplateData: map[string]interface{}{
        "Name": "Nick",
        "Count": 2,
    },
    PluralCount: 2,
}) // Nick has 2 cats.
*/
func (i *Intl) TranslatePlurals(key, lang string) (string, error)