translation: gitoa.ru/go-4devs/translation/icu Index | Examples | Files

package icu

import "gitoa.ru/go-4devs/translation/icu"

Index

Examples

Package Files

trans.go

func SetTranslator Uses

func SetTranslator(tr *translation.Translator)

SetTranslator sets translator.

func Trans Uses

func Trans(ctx context.Context, key string, opts ...translation.Option) string

Trans translate message.

Code:

err := message.Set(language.Russian, "Hello {city}", catalog.String("Привет %s"))
if err != nil {
    log.Fatal(err)
}

err = message.Set(language.Russian, "It costs {cost}", catalog.String("Это стоит %.2f."))
if err != nil {
    log.Fatal(err)
}

lang, err := language.Parse("ru")
if err != nil {
    log.Fatal(err)
}

ctx := translation.WithLanguage(context.Background(), lang)

tr := icu.Trans(ctx, "Hello {city}", translation.WithArgs("Москва"))
fmt.Println(tr)
tr = icu.Trans(ctx, "It costs {cost}", translation.WithNumber("cost", 1000.00, arg.WithNumberFormat(arg.NumberFormatDecimal)))
fmt.Println(tr)

Output:

Привет Москва
Это стоит 1 000,00.

Package icu imports 4 packages (graph). Updated 2020-07-21. Refresh now. Tools for package owners.