locale

package
v0.0.0-...-ecf56c4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

View Source
const AcceptLanguageHeader = "Accept-Language"
View Source
const ContentLanguageHeader = "Content-Language"

Variables

This section is empty.

Functions

func ContentID

func ContentID(cID uint64, i int) uint64

func DetectLanguage

func DetectLanguage(ll *service) func(next http.Handler) http.Handler

func GetAcceptLanguageFromContext

func GetAcceptLanguageFromContext(ctx context.Context) language.Tag

GetAcceptLanguageFromContext always returns language, either valid or default

func GetContentLanguageFromContext

func GetContentLanguageFromContext(ctx context.Context) language.Tag

GetContentLanguageFromContext always returns language, either valid or default

func Global

func Global() *service

Global returns global RBAC service

func LoadEmbedded

func LoadEmbedded() fs.FS

LoadEmbedded returns embedded translation files as a virtual filesystem

func SanitizeMessage

func SanitizeMessage(in string) string

func Service

func Service(log *zap.Logger, opt options.LocaleOpt) (*service, error)

func SetAcceptLanguageToContext

func SetAcceptLanguageToContext(ctx context.Context, code language.Tag) context.Context

func SetContentLanguageToContext

func SetContentLanguageToContext(ctx context.Context, code language.Tag) context.Context

func SetGlobal

func SetGlobal(ll *service)

SetGlobal re-sets global service

func Static

func Static(ll ...*Language) (svc *service)

Types

type ErrorMetaKey

type ErrorMetaKey struct{}

type ErrorMetaNamespace

type ErrorMetaNamespace struct{}

type Language

type Language struct {
	Tag           language.Tag `json:"tag,string"`
	Name          string       `json:"name"`
	LocalizedName string       `json:"localizedName"`

	// Language (tag) that this language is extending
	// @todo
	Extends language.Tag `json:"-"`
	// contains filtered or unexported fields
}

type Locale

type Locale interface {
	T(ctx context.Context, ns, key string, rr ...string) string
	TFor(tag language.Tag, ns, key string, rr ...string) string
	Tags() []language.Tag
}

type Resource

type Resource interface {
	TResource(ctx context.Context, ns, key string, rr ...string) string
	TResourceFor(tag language.Tag, ns, key string, rr ...string) string
	Tags() []language.Tag
	SupportedLang(language.Tag) bool
	ResourceTranslations(code language.Tag, resource string) ResourceTranslationIndex
	Default() *Language
}

type ResourceTranslation

type ResourceTranslation struct {
	Resource string `json:"resource"`
	Lang     string `json:"lang"`
	Key      string `json:"key"`
	Msg      string `json:"message"`
}

type ResourceTranslationIndex

type ResourceTranslationIndex map[string]*ResourceTranslation

func (ResourceTranslationIndex) FindByKey

type ResourceTranslationSet

type ResourceTranslationSet []*ResourceTranslation

func (ResourceTranslationSet) ContainsForeign

func (rr ResourceTranslationSet) ContainsForeign(native language.Tag) bool

Returns true if resource translation set contains foreign (non-native) languages

func (ResourceTranslationSet) SetLanguage

func (rr ResourceTranslationSet) SetLanguage(tag language.Tag)

Jump to

Keyboard shortcuts

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