localize

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: BSD-3-Clause, MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context = string

Context is an alias type for string which is used by xspreak for extracting strings.

type Domain

type Domain = string

Domain is an alias type for string which is used by xspreak for extracting strings.

type Error

type Error struct {
	Translation string
	Wrapped     error
}

Error is returned when a Localizer or Locale translates an error into the target language.

func (*Error) Error

func (e *Error) Error() string

func (*Error) String

func (e *Error) String() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Key added in v0.3.0

type Key = string

Key is an alias type for string which is used by xspreak for extracting strings. The exported key is not stored as text, only the key is stored. Should only be used when messages are identified by keys and not by strings. For example when using JSON.

type Localizable

type Localizable interface {
	// GetMsgID specifies the message id (singular) for which the message should be translated.
	GetMsgID() string
	// GetPluralID specifies the plural for which the message should be translated.
	GetPluralID() string
	// GetContext specifies the context for which the message should be translated.
	GetContext() string
	// GetVars is optional, can be used to pass parameters.
	GetVars() []interface{}
	GetCount() int
	// HasDomain specifies whether the domain of Domain() is to be used.
	// If false the default domain is used.
	HasDomain() bool
	// GetDomain specifies the domain for which the message should be translated.
	GetDomain() string
}

A Localizable allows access to a message that needs to be translated.

An implementation can be passed directly to a spreak.Localizer or spreak.Locale via l.Localize(impl) to obtain a translation.

type Message

type Message struct {
	Singular Singular
	Plural   Plural
	Context  Context
	Vars     []interface{}
	Count    int
}

Message is a simple struct representing a message without a domain. Can be converted to a translated string by spreak.Localizer or spreak.Locale.

func (*Message) GetContext

func (m *Message) GetContext() string

func (*Message) GetCount

func (m *Message) GetCount() int

func (*Message) GetDomain

func (m *Message) GetDomain() string

func (*Message) GetMsgID

func (m *Message) GetMsgID() string

func (*Message) GetPluralID

func (m *Message) GetPluralID() string

func (*Message) GetVars

func (m *Message) GetVars() []interface{}

func (*Message) HasDomain

func (m *Message) HasDomain() bool

type MsgID

type MsgID = string

MsgID is an alias type for string which is used by xspreak for extracting strings MsgID and Singular are synonymous and both represent the ID to identify the message.

type Plural

type Plural = string

Plural is an alias type for string which is used by xspreak for extracting strings.

type PluralKey added in v0.3.0

type PluralKey = string

PluralKey is an alias type for string which is used by xspreak for extracting strings. It represents a MsgId AND a PluralId which identify a message. The exported key is not stored as text, only the key is stored. Should only be used when messages are identified by keys and not by strings. For example when using JSON.

type Singular

type Singular = string

Singular is an alias type for string which is used by xspreak for extracting strings MsgID and Singular are synonymous and both represent the ID to identify the message.

Jump to

Keyboard shortcuts

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