locale

package
v0.0.0-...-41e44c1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Supported = []string{"en-US", "nl-NL"}

Supported languages

Functions

func ErrorMessage

func ErrorMessage(err error) string

func HasError

func HasError(err error) bool

HasError checks the error chain for an ErrorLocalizer

func IsError

func IsError(err error) bool

IsError checks if the given error is an ErrorLocalizer

func IsInputError

func IsInputError(err error) bool

IsInputError checks if the given error contains a InputError anywhere in the unwrap stack

func IsInputErrorNonRecursive

func IsInputErrorNonRecursive(err error) bool

IsInputErrorNonRecursive checks if the given error is an InputError

func JoinedErrorMessage

func JoinedErrorMessage(err error) string

JoinedErrorMessage joins all error messages in the Unwrap stack that are localized

func Set

func Set(localeName string) (rerr error)

Set the active language to the given locale

func T

func T(translationID string, args ...interface{}) string

T aliases to i18n.Tfunc()

func Tl

func Tl(translationID, locale string, values ...string) string

Tl is like Tr but it accepts a fallback locale for if the translationID is not found

func Tr

func Tr(translationID string, values ...string) string

Tr is like T but it accepts string params that will be used as numbered params, eg. V0, V1, V2 etc

func Ts

func Ts(translationIDs ...string) []string

Ts aliases to T, but accepts a list of translationIDs to be translated

func Tt

func Tt(translationID string, args ...interface{}) string

Tt aliases to T, but before returning the string it replaces `[[` and `]]` with `{{` and `}}`, allowing for the localized strings to use these template tags without triggering i18n

func UnpackError

func UnpackError(err error) []error

UnpackError recursively unpacks the given error and returns all localized errors

Types

type AsError

type AsError interface {
	As(interface{}) bool
}

type ErrorInput

type ErrorInput interface {
	InputError() bool
}

ErrorInput represents a user input error

type ErrorLocalizer

type ErrorLocalizer interface {
	error
	LocaleError() string
}

ErrorLocalizer represents a localized error

type LocalizedError

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

LocalizedError is an error that has the concept of user facing (localized) errors as well as whether an error is due to user input or not

func NewError

func NewError(id string, args ...string) *LocalizedError

NewError creates a new error, it does a locale.Tl lookup of the given id, if the lookup fails it will use the locale string instead

func NewExternalError

func NewExternalError(id string, args ...string) *LocalizedError

func NewInputError

func NewInputError(id string, args ...string) *LocalizedError

NewInputError is like NewError but marks it as an input error

func WrapError

func WrapError(err error, id string, args ...string) *LocalizedError

WrapError creates a new error that wraps the given error, it does a locale.Tt lookup of the given id, if the lookup fails it will use the locale string instead

func WrapExternalError

func WrapExternalError(wrapTarget error, id string, args ...string) *LocalizedError

func WrapInputError

func WrapInputError(err error, id string, args ...string) *LocalizedError

WrapInputError is like WrapError but marks it as an input error

func (*LocalizedError) AddTips

func (e *LocalizedError) AddTips(tips ...string)

func (*LocalizedError) Error

func (e *LocalizedError) Error() string

Error is the error message

func (*LocalizedError) ErrorTips

func (e *LocalizedError) ErrorTips() []string

func (*LocalizedError) ExternalError

func (e *LocalizedError) ExternalError() bool

func (*LocalizedError) InputError

func (e *LocalizedError) InputError() bool

InputError returns whether this is an error due to user input

func (*LocalizedError) LocaleError

func (e *LocalizedError) LocaleError() string

LocaleError is the user facing error message, it's the same as Error() but identifies it as being user facing

func (*LocalizedError) Stack

func (e *LocalizedError) Stack() *stacktrace.Stacktrace

Stack is the stacktrace leading up to where this error was triggered

func (*LocalizedError) Unwrap

func (e *LocalizedError) Unwrap() error

Unwrap returns the parent error, if applicable

Jump to

Keyboard shortcuts

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