README

translation

Build Status Go Report Card GoDoc

Expand ▾ Collapse ▴

Documentation

Index

Examples

Constants

View Source
const (
	DefaultDomain = "messages"
)

    Default values.

    Variables

    This section is empty.

    Functions

    func FromContext

    func FromContext(ctx context.Context, def language.Tag) language.Tag

      FromContext get language from context or use default.

      func WithLanguage

      func WithLanguage(ctx context.Context, lang language.Tag) context.Context

        WithLanguage sets language to context.

        Types

        type Arg

        type Arg interface {
        	Val() interface{}
        	fmt.Stringer
        }

          Arg arg translate.

          type Option

          type Option func(*Translate)

            Option configures translate.

            func WithArgs

            func WithArgs(vals ...interface{}) Option

              WithArgs sets arguments value.

              func WithCurrency

              func WithCurrency(key string, val interface{}, opts ...arg.CurrencyOption) Option

                WithCurrency sets date argument.

                func WithDomain

                func WithDomain(domain string) Option

                  WithDomain sets domain translate.

                  func WithLocale

                  func WithLocale(locale string) Option

                    WithLocale sets locale translate.

                    func WithNumber

                    func WithNumber(key string, val interface{}, opts ...arg.NumberOption) Option

                      WithNumber sets number with options.

                      type Provider

                      type Provider interface {
                      	Translate(ctx context.Context, key string, opt Translate) string
                      }

                        Provider for translate key.

                        type Translate

                        type Translate struct {
                        	Domain string
                        	Locale language.Tag
                        	Args   []Arg
                        }

                          Translate configure translate.

                          func (*Translate) ArgValues

                          func (t *Translate) ArgValues() []interface{}

                            ArgValues gets value arguments.

                            type Translator

                            type Translator struct {
                            	// contains filtered or unexported fields
                            }

                              Translator struct.

                              func New

                              func New(locale language.Tag, provider Provider, opts ...TranslatorOption) *Translator

                                New creates new translator.

                                func (*Translator) Trans

                                func (t *Translator) Trans(ctx context.Context, key string, opts ...Option) string

                                  Trans translates key by options.

                                  Example
                                  Output:
                                  
                                  Привет Мир!
                                  Hello World!
                                  Ahoj Svet!
                                  שלום עולם
                                  Привет Andrey!
                                  Вы опоздали на одну минуту.
                                  Вы вовремя.
                                  Вы опоздали на 101 минуту.
                                  Вы опоздали на 123 456,78 минут.
                                  Вы опоздали на 50 минут.
                                  You are 1 minute late.
                                  You are 33 minutes late.
                                  В каждом доме есть 1,2 велосипеда.
                                  There are 1.2 bikes per household.
                                  Это стоит ₽ 12.0101.
                                  It costs HK$ 15.
                                  

                                  type TranslatorOption

                                  type TranslatorOption func(*Translator)

                                    TranslatorOption options translator.

                                    Directories

                                    Path Synopsis
                                    provider