i18nerr

package
v0.0.0-...-580f94b Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package i18nerr implements errors with internationalization using gotext

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TranslatedInner

func TranslatedInner(inner error) (string, bool)

TranslatedInner defines errors that are used as inner causes but are still translated because they can happen frequently

Types

type Error

type Error struct {
	Misc bool
	// contains filtered or unexported fields
}

Error wraps an actual error with the translation key This translation key is later used to lookup translation The inner error always consists of the translation key and some formatting

func New

func New(key message.Reference) *Error

New creates a new i18n error using a message reference

func NewInternal

func NewInternal(disp string) *Error

NewInternal creates an internal localised error from a display string

func NewInternalf

func NewInternalf(disp string, args ...interface{}) *Error

NewInternalf creates an internal localised error from a display string and arguments

func Newf

func Newf(key message.Reference, args ...interface{}) *Error

Newf creates a new i18n error using a message reference and arguments. It formats this with fmt.Errorf

func Wrap

func Wrap(err error, key message.Reference) *Error

Wrap creates a new i18n error using an error to be wrapped 'err' and a prefix message reference 'key'. It formats this with fmt.Errorf

func WrapInternal

func WrapInternal(err error, disp string) *Error

WrapInternal wraps an error and a display string into a localised internal error

func WrapInternalf

func WrapInternalf(err error, disp string, args ...interface{}) *Error

WrapInternalf wraps an error and a display string with args into a localised internal error

func Wrapf

func Wrapf(err error, key message.Reference, args ...interface{}) *Error

Wrapf creates a new i18n error using an error to be wrapped 'err' and a prefix message reference 'key' with format arguments 'args'. It formats this with fmt.Errorf

func (*Error) Error

func (e *Error) Error() string

Error gets the error string it does this by simply forwarding the error method from the actual inner error

func (*Error) Translations

func (e *Error) Translations() map[string]string

Translations returns all the translations for the error including the source translation (english)

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the unwrapped error it does this by unwrapping the inner error

Jump to

Keyboard shortcuts

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