mrlang

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseAcceptLanguage

func ParseAcceptLanguage(s string) []string

ParseAcceptLanguage Sample Accept-Language: ru;q=0.9, fr-CH, fr;q=0.8, en;q=0.7, *;q=0.5

func WithContext added in v0.7.1

func WithContext(ctx context.Context, locale *Locale) context.Context

Types

type Dictionary added in v0.6.0

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

func (*Dictionary) ItemByID added in v0.6.0

func (d *Dictionary) ItemByID(id int) DictionaryItemAttrs

func (*Dictionary) ItemByKey added in v0.6.0

func (d *Dictionary) ItemByKey(key string) DictionaryItemAttrs

func (*Dictionary) RegisteredItems added in v0.6.0

func (d *Dictionary) RegisteredItems() []string

type DictionaryItemAttrs added in v0.6.0

type DictionaryItemAttrs map[string]string

func (DictionaryItemAttrs) Attr added in v0.6.0

func (a DictionaryItemAttrs) Attr(name, defaultText string) string

func (DictionaryItemAttrs) RegisteredAttrs added in v0.6.0

func (a DictionaryItemAttrs) RegisteredAttrs() []string

type DictionaryMap added in v0.6.0

type DictionaryMap map[string]DictionaryItemAttrs // dictionary-name -> [id -> [attr1 -> text1, attr2 -> text2, ...], ...]

type Locale

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

func Ctx added in v0.7.1

func Ctx(ctx context.Context) *Locale

func (*Locale) HasErrorCode added in v0.7.1

func (l *Locale) HasErrorCode(code string) bool

func (*Locale) LangCode

func (l *Locale) LangCode() string

func (*Locale) LangID added in v0.6.0

func (l *Locale) LangID() uint16

func (*Locale) TranslateError

func (l *Locale) TranslateError(code, defaultMessage string, args ...mrmsg.NamedArg) mrmsg.ErrorMessage

func (*Locale) TranslateMessage

func (l *Locale) TranslateMessage(code, defaultMessage string, args ...mrmsg.NamedArg) string

func (*Locale) WithContext added in v0.7.1

func (l *Locale) WithContext(ctx context.Context) context.Context

type MultiLangDictionary added in v0.6.0

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

func (*MultiLangDictionary) ByLangCode added in v0.6.0

func (d *MultiLangDictionary) ByLangCode(code string) (*Dictionary, error)

func (*MultiLangDictionary) ByLangID added in v0.6.0

func (d *MultiLangDictionary) ByLangID(id uint16) (*Dictionary, error)

func (*MultiLangDictionary) Name added in v0.6.0

func (d *MultiLangDictionary) Name() string

func (*MultiLangDictionary) RegisteredLangs added in v0.6.0

func (d *MultiLangDictionary) RegisteredLangs() []string

type Translator

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

func NewTranslator

func NewTranslator(opts TranslatorOptions) (*Translator, error)

func (*Translator) DefaultLocale added in v0.3.0

func (t *Translator) DefaultLocale() *Locale

func (*Translator) Dictionary added in v0.6.0

func (t *Translator) Dictionary(name string) (*MultiLangDictionary, error)

func (*Translator) FindFirstLocale added in v0.1.1

func (t *Translator) FindFirstLocale(langs ...string) *Locale

FindFirstLocale - if not exists get default locale

func (*Translator) LocaleByCode added in v0.6.0

func (t *Translator) LocaleByCode(lang string) (*Locale, error)

func (*Translator) LocaleByID added in v0.6.0

func (t *Translator) LocaleByID(langID uint16) (*Locale, error)

func (*Translator) RegisteredDictionaries added in v0.6.0

func (t *Translator) RegisteredDictionaries() []string

func (*Translator) RegisteredLocales

func (t *Translator) RegisteredLocales() []string

type TranslatorOptions

type TranslatorOptions struct {
	DirPath           string
	LangCodes         []string
	DefaultLang       string // optional
	DictionaryDirPath string
	Dictionaries      []string // optional
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL