i18n

package module
v0.0.0-...-cf35c26 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadTranslationFiles

func LoadTranslationFiles(path string, translations DomainTranslations, domain *Domain)

func TranslatorFilter

func TranslatorFilter(options ...OptionFn) factory.AppendFilterFn

TranslatorFilter {{ message|trans(arguments = [], domain = null, locale = null) }}

func WithTranslator

func WithTranslator(translator *Translator) factory.AppendFilterFn

Types

type Domain

type Domain string

type DomainTranslations

type DomainTranslations map[Domain]LocaleTranslations

type Loader

type Loader = func() []byte

func FileLoader

func FileLoader(path string) Loader

type Locale

type Locale string

type LocaleTranslations

type LocaleTranslations map[Locale]Translations

type Option

type Option struct {
	DefaultLocale      Locale
	DefaultDomain      Domain
	DomainTranslations DomainTranslations
	Translation        LocaleTranslations
}

func (*Option) Value

func (o *Option) Value(key string, locale Locale, domain Domain) (string, bool)

type OptionFn

type OptionFn func(*Option)

func AddDomainTranslations

func AddDomainTranslations(domain, locale string, loader Loader) OptionFn

func WithDefaultDomain

func WithDefaultDomain() OptionFn

func WithDefaultTranslations

func WithDefaultTranslations(translations LocaleTranslations) OptionFn

func WithDomain

func WithDomain(domain string) OptionFn

func WithLocale

func WithLocale(locale string) OptionFn

func WithLocalizationPath

func WithLocalizationPath(path string) OptionFn

func WithTranslations

func WithTranslations(translations DomainTranslations) OptionFn

type TranslationFilter

type TranslationFilter struct {
	Translator
}

func (*TranslationFilter) Register

func (f *TranslationFilter) Register(filters map[string]stick.Filter)

func (*TranslationFilter) Trans

func (f *TranslationFilter) Trans(ctx stick.Context, value stick.Value, args ...stick.Value) stick.Value

type Translations

type Translations map[string]string

type Translator

type Translator struct {
	Domain         Domain
	Locale         Locale
	SelectedLocale Locale

	Translations       map[string]string
	LocaleTranslations map[Locale]Translations
	DomainTranslations map[Domain]LocaleTranslations
}

func GetTranslator

func GetTranslator(opts ...OptionFn) *Translator

func NewTranslator

func NewTranslator(opts ...OptionFn) *Translator

func (*Translator) GetDomain

func (t *Translator) GetDomain(domain Domain) Domain

func (*Translator) GetLocale

func (t *Translator) GetLocale(locale Locale) Locale

func (*Translator) SetLocale

func (t *Translator) SetLocale(locale Locale)

func (*Translator) Translate

func (t *Translator) Translate(
	ctx context.Context,
	key string,
	args map[string]string,
	locale Locale,
	domain Domain,
) string

Jump to

Keyboard shortcuts

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