i18n

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 10 Imported by: 21

Documentation

Index

Constants

View Source
const ExtendioSourceID = "github.com/snivilised/extendio"

ExtendioSourceID the id that represents this module. If client want to provides translations for languages that extendio does not, then the localizer the create created for this purpose should use this SourceID. So whenever the Text function is used on templates defined inside this module, the translation process is directed to use the correct i18n.Localizer (identified by the SourceID). The Source is statically defined for all templates defined in extendio.

Variables

Functions

func NewCouldNotFindLocalizerNativeError

func NewCouldNotFindLocalizerNativeError(sourceID string) error

NewFailedToCreateLocalizerNativeError creates an untranslated error to indicate the Translator already contains a localizer for the source specified. (internal error)

func NewCouldNotLoadTranslationsNativeError

func NewCouldNotLoadTranslationsNativeError(tag language.Tag, path string, reason error) error

NewCouldNotLoadTranslationsNativeError creates an untranslated error to indicate translations file could not be loaded

func NewFailedToCreateTranslatorNativeError

func NewFailedToCreateTranslatorNativeError(tag language.Tag) error

NewFailedToCreateTranslatorNativeError creates an untranslated error to indicate failure to create a Translator instance

func QueryFailedToReadDirectoryContentsError

func QueryFailedToReadDirectoryContentsError(target error) bool

QueryFailedToReadDirectoryContentsError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryFailedToResumeFromFileError

func QueryFailedToResumeFromFileError(target error) bool

QueryFailedToResumeFromFileError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryGeneric

func QueryGeneric[T any](method string, target error) bool

func QueryInvalidConfigEntryError

func QueryInvalidConfigEntryError(target error) bool

QueryInvalidConfigEntryError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryInvalidResumeStrategyError

func QueryInvalidResumeStrategyError(target error) bool

QueryInvalidResumeStrategyError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryMissingCallbackError

func QueryMissingCallbackError(target error) bool

QueryMissingCallbackError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryMissingCustomFilterDefinitionError

func QueryMissingCustomFilterDefinitionError(target error) bool

QueryMissingCustomFilterDefinitionError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryNotADirectoryError

func QueryNotADirectoryError(target error) bool

QueryNotADirectoryError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryPathNotFoundError added in v0.1.18

func QueryPathNotFoundError(target error) bool

QueryPathNotFoundError helper function to enable identification of an error via its behaviour, rather than by its type.

func QuerySortFnFailedError

func QuerySortFnFailedError(target error) bool

QuerySortFnFailedError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryTerminateTraverseError

func QueryTerminateTraverseError(target error) bool

QueryTerminateTraverseError helper function to enable identification of an error via its behaviour, rather than by its type.

func QueryUnknownMarshalFormatError

func QueryUnknownMarshalFormatError(target error) bool

QueryUnknownMarshalFormatError helper function to enable identification of an error via its behaviour, rather than by its type.

func ResetTx

func ResetTx()

ResetTx, do not use, required for unit testing only and is not considered part of the public api and may be removed without corresponding version number change.

func Text

func Text(data Localisable) string

Text is the function to use to obtain a string created from registered Localizers. The data parameter must be a go template defining the input parameters and the translatable message content.

func Use

func Use(options ...UseOptionFn) error

Use, must be called by the client before any string data can be translated. If the client requests the default language, then only the language Tag needs to be provided. If the requested language is not the default and therefore requires translation from the translation file(s), then the client must provide the App and Path properties indicating how the l18n bundle is created. If the client just wishes to use the Default language, then Use can even be called without specifying the Tag and in this case the default language will be used. The client MUST call Use before using any functionality in this package.

Types

type AbstractTranslatorFactory added in v0.1.10

type AbstractTranslatorFactory struct {
	Create LocalizerCreatorFn
	// contains filtered or unexported fields
}

type ExtendioTemplData

type ExtendioTemplData struct{}

func (ExtendioTemplData) SourceID added in v0.1.13

func (td ExtendioTemplData) SourceID() string

type FailedToReadDirectoryContentsError

type FailedToReadDirectoryContentsError struct {
	LocalisableError
}

func NewFailedToReadDirectoryContentsError

func NewFailedToReadDirectoryContentsError(path string, reason error) FailedToReadDirectoryContentsError

NewFailedToReadDirectoryContentsError creates a FailedToReadDirectoryContentsError

func (FailedToReadDirectoryContentsError) FailedToReadDirectoryContents

func (e FailedToReadDirectoryContentsError) FailedToReadDirectoryContents() bool

FailedToReadDirectoryContents enables the client to check if error is FailedToReadDirectoryContentsError via QueryFailedToReadDirectoryContentsError

type FailedToReadDirectoryContentsErrorBehaviourQuery

type FailedToReadDirectoryContentsErrorBehaviourQuery interface {
	FailedToReadDirectoryContents() bool
}

FailedToReadDirectoryContentsErrorBehaviourQuery used to query if an error is: "Failed to read directory contents from the path specified"

type FailedToReadDirectoryContentsTemplData

type FailedToReadDirectoryContentsTemplData struct {
	ExtendioTemplData
	Path   string
	Reason error
}

FailedToReadDirectoryContentsTemplData failed to resume using file

func (FailedToReadDirectoryContentsTemplData) Message

type FailedToResumeFromFileError

type FailedToResumeFromFileError struct {
	LocalisableError
}

func NewFailedToResumeFromFileError

func NewFailedToResumeFromFileError(path string, reason error) FailedToResumeFromFileError

NewFailedToResumeFromFileError creates a FailedToResumeFromFileError

func (FailedToResumeFromFileError) FailedToResumeFromFile

func (e FailedToResumeFromFileError) FailedToResumeFromFile() bool

FailedToResumeFromFile enables the client to check if error is FailedToResumeFromFileError via QueryFailedToResumeFromFileError

type FailedToResumeFromFileErrorBehaviourQuery

type FailedToResumeFromFileErrorBehaviourQuery interface {
	FailedToResumeFromFile() bool
}

FailedToResumeFromFileErrorBehaviourQuery used to query if an error is: "Failed to resume traverse operation from the resume file specified"

type FailedToResumeFromFileTemplData

type FailedToResumeFromFileTemplData struct {
	ExtendioTemplData
	Path   string
	Reason error
}

FailedToResumeFromFileTemplData failed to resume using file

func (FailedToResumeFromFileTemplData) Message

type InternationalisationTemplData

type InternationalisationTemplData struct {
	ExtendioTemplData
}

Internationalisation

func (InternationalisationTemplData) Message

func (td InternationalisationTemplData) Message() *Message

type InvalidConfigEntryError

type InvalidConfigEntryError struct {
	LocalisableError
}

func NewInvalidConfigEntryError

func NewInvalidConfigEntryError(value, at string) InvalidConfigEntryError

NewInvalidConfigEntryError creates a InvalidConfigEntryError

func (InvalidConfigEntryError) InvalidConfigEntry

func (e InvalidConfigEntryError) InvalidConfigEntry() bool

InvalidConfigEntry enables the client to check if error is InvalidConfigEntryError via QueryInvalidConfigEntryError

type InvalidConfigEntryErrorBehaviourQuery

type InvalidConfigEntryErrorBehaviourQuery interface {
	InvalidConfigEntry() bool
}

InvalidConfigEntryErrorBehaviourQuery used to query if an error is: "Failed to resume traverse operation from the resume file specified"

type InvalidConfigEntryTemplData

type InvalidConfigEntryTemplData struct {
	ExtendioTemplData
	Value string
	At    string
}

InvalidConfigEntryTemplData failed to resume using file

func (InvalidConfigEntryTemplData) Message

func (td InvalidConfigEntryTemplData) Message() *Message

type InvalidResumeStrategyError

type InvalidResumeStrategyError struct {
	LocalisableError
}

func NewInvalidResumeStrategyError

func NewInvalidResumeStrategyError(value string) InvalidResumeStrategyError

NewInvalidResumeStrategyError creates a InvalidResumeStrategyError

func (InvalidResumeStrategyError) InvalidResumeStrategy

func (e InvalidResumeStrategyError) InvalidResumeStrategy() bool

InvalidResumeStrategy enables the client to check if error is InvalidResumeStrategyError via QueryInvalidResumeStrategyError

type InvalidResumeStrategyErrorBehaviourQuery

type InvalidResumeStrategyErrorBehaviourQuery interface {
	InvalidResumeStrategy() bool
}

InvalidResumeStrategyErrorBehaviourQuery used to query if an error is: "Failed to resume traverse operation from the resume file specified"

type InvalidResumeStrategyTemplData

type InvalidResumeStrategyTemplData struct {
	ExtendioTemplData
	Value string
}

InvalidResumeStrategyTemplData failed to resume using file

func (InvalidResumeStrategyTemplData) Message

type LanguageInfo

type LanguageInfo struct {
	UseOptions

	// Default language reflects the base language. If all else fails, messages will
	// be in this language. It is fixed at BritishEnglish reflecting the language this
	// package is written in.
	//
	Default language.Tag

	// Supported indicates the list of languages for which translations are available.
	//
	Supported SupportedLanguages
}

func NewLanguageInfo added in v0.1.7

func NewLanguageInfo(o *UseOptions) *LanguageInfo

NewLanguageInfo gets a new instance of Language info from the use options specified. This is specific to extendio. Client applications should provide their own version that reflects their own defaults.

type LoadFrom added in v0.1.7

type LoadFrom struct {
	// Path denoting where to load language file from, defaults to exe location
	//
	Path string

	// Sources are the translation files that need to be loaded. They represent
	// the client app/library its dependencies.
	//
	// The source id would typically be the name of a package that is the source
	// of string messages that are to be translated. Actually, we could use
	// the top level url of the package by convention, as that is unique.
	// So extendio would use "github.com/snivilised/extendio" but clients
	// are free to use whatever naming scheme they want to use for their own
	// dependencies.
	//
	Sources TranslationFiles
}

LoadFrom denotes where to load the translation file from

func (*LoadFrom) AddSource added in v0.1.16

func (lf *LoadFrom) AddSource(sourceID string, source *TranslationSource)

AddSource adds a translation source

type Localisable

type Localisable interface {
	Message() *Message
	SourceID() string
}

type LocalisableError

type LocalisableError struct {
	Data Localisable
}

LocalisableError is an error that is translate-able (Localisable)

func (LocalisableError) Error

func (le LocalisableError) Error() string

type LocalisationTemplData

type LocalisationTemplData struct {
	ExtendioTemplData
}

Internationalisation

func (LocalisationTemplData) Message

func (td LocalisationTemplData) Message() *Message

type LocalizeConfig added in v0.1.14

type LocalizeConfig = i18n.LocalizeConfig

type Localizer added in v0.1.14

type Localizer = i18n.Localizer

type LocalizerCreatorFn added in v0.1.7

type LocalizerCreatorFn func(li *LanguageInfo, sourceID string) (*Localizer, error)

LocalizerCreatorFn represents the signature of the function can optionally provide to override how an i18n Localizer is created.

type LocalizerInfo

type LocalizerInfo struct {
	// Localizer by default created internally, but can be overridden by
	// the client if they provide a create function to the Translator Factory
	//
	Localizer *Localizer
	// contains filtered or unexported fields
}

LocalizerInfo

type Message added in v0.1.14

type Message = i18n.Message

type MissingCallbackBehaviourQuery

type MissingCallbackBehaviourQuery interface {
	MissingCallback() bool
}

MissingCallbackBehaviourQuery used to query if an error is: "Missing callback (internal error)"

type MissingCallbackError

type MissingCallbackError struct {
	LocalisableError
}

MissingCallbackError, this is a coding error where client has not provided a callback required by the api.

func NewMissingCallbackError

func NewMissingCallbackError() MissingCallbackError

NewMissingCallbackError creates a MissingCallbackError

func (MissingCallbackError) MissingCallback

func (e MissingCallbackError) MissingCallback() bool

MissingCallback enables the client to check if error is MissingCallbackError via QueryMissingCallbackError

type MissingCallbackTemplData

type MissingCallbackTemplData struct {
	ExtendioTemplData
}

missing callback (internal)

func (MissingCallbackTemplData) Message

func (td MissingCallbackTemplData) Message() *Message

type MissingCustomFilterDefinitionBehaviourQuery

type MissingCustomFilterDefinitionBehaviourQuery interface {
	MissingCustomFilterDefinition() bool
}

MissingCustomFilterDefinitionBehaviourQuery used to query if an error is: "Missing callback (internal error)"

type MissingCustomFilterDefinitionError

type MissingCustomFilterDefinitionError struct {
	LocalisableError
}

MissingCustomFilterDefinitionError, this is a config error where client has not provided the definition of a custom filter having set the filter type to custom and a pattern

func NewMissingCustomFilterDefinitionError

func NewMissingCustomFilterDefinitionError(at string) MissingCustomFilterDefinitionError

NewMissingCustomFilterDefinitionError creates a MissingCustomFilterDefinitionError

func (MissingCustomFilterDefinitionError) MissingCustomFilterDefinition

func (e MissingCustomFilterDefinitionError) MissingCustomFilterDefinition() bool

MissingCustomFilterDefinition enables the client to check if error is MissingCustomFilterDefinitionError via QueryMissingCustomFilterDefinitionError

type MissingCustomFilterDefinitionTemplData

type MissingCustomFilterDefinitionTemplData struct {
	ExtendioTemplData
	At string
}

Missing custom filter definition (config)

func (MissingCustomFilterDefinitionTemplData) Message

type NotADirectoryError

type NotADirectoryError struct {
	LocalisableError
}

func NewNotADirectoryError

func NewNotADirectoryError(path string) NotADirectoryError

NewNotADirectoryError creates a NotADirectoryError

func (NotADirectoryError) NotADirectory

func (e NotADirectoryError) NotADirectory() bool

NotADirectory enables the client to check if error is NotADirectoryError via QueryNotADirectoryError

type NotADirectoryErrorBehaviourQuery

type NotADirectoryErrorBehaviourQuery interface {
	NotADirectory() bool
}

NotADirectoryErrorBehaviourQuery used to query if an error is: "File system path is not a directory"

type NotADirectoryTemplData

type NotADirectoryTemplData struct {
	ExtendioTemplData
	Path string
}

NotADirectoryTemplData path is not a directory

func (NotADirectoryTemplData) Message

func (td NotADirectoryTemplData) Message() *Message

type PathNotFoundError added in v0.1.18

type PathNotFoundError struct {
	LocalisableError
}

func NewPathNotFoundError added in v0.1.18

func NewPathNotFoundError(name, path string) PathNotFoundError

NewPathNotFoundError creates a PathNotFoundError

func (PathNotFoundError) IsPathNotFound added in v0.1.18

func (e PathNotFoundError) IsPathNotFound() bool

PathNotFound enables the client to check if error is PathNotFoundError via QueryPathNotFoundError

type PathNotFoundErrorBehaviourQuery added in v0.1.18

type PathNotFoundErrorBehaviourQuery interface {
	IsPathNotFound() bool
}

PathNotFoundErrorBehaviourQuery used to query if an error is: "File system foo is ..."

type PathNotFoundTemplData added in v0.1.18

type PathNotFoundTemplData struct {
	ExtendioTemplData
	Name string
	Path string
}

PathNotFoundTemplData is

func (PathNotFoundTemplData) Message added in v0.1.18

func (td PathNotFoundTemplData) Message() *Message

type SortFnFailedBehaviourQuery

type SortFnFailedBehaviourQuery interface {
	SortFnFailed() bool
}

SortFnFailedBehaviourQuery used to query if an error is: "Sort function failed (internal error)"

type SortFnFailedError

type SortFnFailedError struct {
	LocalisableError
}

func NewSortFnFailedError

func NewSortFnFailedError() SortFnFailedError

NewSortFnFailedError creates a SortFnFailedError

func (SortFnFailedError) SortFnFailed

func (e SortFnFailedError) SortFnFailed() bool

SortFnFailed enables the client to check if error is SortFnFailedError via QuerySortFnFailedError

func (SortFnFailedError) TerminateTraverse

func (e SortFnFailedError) TerminateTraverse() bool

TerminateTraverse enables the client to check if error is SortFnFailedError via QueryTerminateTraverseError

type SortFnFailedTemplData

type SortFnFailedTemplData struct {
	ExtendioTemplData
}

sort function failed (internal)

func (SortFnFailedTemplData) Message

func (td SortFnFailedTemplData) Message() *Message

type SupportedLanguages

type SupportedLanguages []language.Tag

type TerminateTraverseBehaviourQuery

type TerminateTraverseBehaviourQuery interface {
	TraverseTerminated() bool
}

TerminateTraverseBehaviourQuery used to query if an error is: "Traversal terminated"

type TerminateTraverseError

type TerminateTraverseError struct {
	LocalisableError
}

TerminateTraverseError indicates that traversal has been terminated early

func NewTerminateTraverseError

func NewTerminateTraverseError() TerminateTraverseError

NewTerminateTraverseError creates a TerminateTraverseError

type TerminateTraverseTemplData

type TerminateTraverseTemplData struct {
	ExtendioTemplData
	Reason string
}

terminate traverse

func (TerminateTraverseTemplData) Message

func (td TerminateTraverseTemplData) Message() *Message

type ThirdPartyError

type ThirdPartyError struct {
	LocalisableError
}

ThirdPartyError represents an error received by a dependency that does not support i18n.

func NewThirdPartyErr

func NewThirdPartyErr(err error) ThirdPartyError

NewThirdPartyErr creates a ThirdPartyErr

type ThirdPartyErrorTemplData

type ThirdPartyErrorTemplData struct {
	ExtendioTemplData

	Error error
}

ThirdPartyErrorTemplData third party un-translated error

func (ThirdPartyErrorTemplData) Message

func (td ThirdPartyErrorTemplData) Message() *Message

type TranslationFiles added in v0.1.7

type TranslationFiles map[string]TranslationSource

TranslationFiles maps a source id to a TranslationSource

type TranslationSource added in v0.1.7

type TranslationSource struct {
	// Name of dependency's translation file
	Name string
	Path string
}

type Translator

type Translator interface {
	Localise(data Localisable) string
	LanguageInfoRef() utils.RoProp[*LanguageInfo]
	// contains filtered or unexported methods
}

type TranslatorFactory added in v0.1.7

type TranslatorFactory interface {
	New(lang *LanguageInfo) Translator
}

TranslatorFactory

type UnknownMarshalFormatError

type UnknownMarshalFormatError struct {
	LocalisableError
}

func NewUnknownMarshalFormatError

func NewUnknownMarshalFormatError(format, at string) UnknownMarshalFormatError

NewUnknownMarshalFormatError creates a UnknownMarshalFormatError

func (UnknownMarshalFormatError) UnknownMarshalFormat

func (e UnknownMarshalFormatError) UnknownMarshalFormat() bool

UnknownMarshalFormat enables the client to check if error is UnknownMarshalFormatError via QueryUnknownMarshalFormatError

type UnknownMarshalFormatErrorBehaviourQuery

type UnknownMarshalFormatErrorBehaviourQuery interface {
	UnknownMarshalFormat() bool
}

UnknownMarshalFormatErrorBehaviourQuery used to query if an error is: "Unknown marshal format specified in config"

type UnknownMarshalFormatTemplData

type UnknownMarshalFormatTemplData struct {
	ExtendioTemplData
	Format string
	At     string
}

UnknownMarshalFormatTemplData unknown marshall format specified in config by user

func (UnknownMarshalFormatTemplData) Message

func (td UnknownMarshalFormatTemplData) Message() *Message

type UseOptionFn

type UseOptionFn func(*UseOptions)

UseOptionFn functional options function required by Use.

type UseOptions

type UseOptions struct {
	// Tag sets the language to use
	//
	Tag language.Tag

	// From denotes where to load the translation file from
	//
	From LoadFrom

	// DefaultIsAcceptable controls whether an error is returned if the
	// request language is not available. By default DefaultIsAcceptable
	// is true so that the application continues in the default language
	// even if the requested language is not available.
	//
	DefaultIsAcceptable bool

	// Create allows the client to  override the default function to create
	// the i18n Localizer(s) (1 per language).
	//
	Create LocalizerCreatorFn

	// Custom set-able by the client for what ever purpose is required.
	//
	Custom any
}

UseOptions the options provided to the Use function

Jump to

Keyboard shortcuts

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