Documentation ¶
Overview ¶
Package langs contains the full list of abreviations of locales available to the system.
Index ¶
- Constants
- Variables
- func IsValid(lang string) bool
- func NativeName(lang Lang) string
- type Chain
- type ChainOption
- type Content
- func (content *Content) Clear(lang Lang)
- func (content *Content) ClearAll()
- func (content Content) Get(lang Lang) string
- func (content Content) GetChain(lang Lang, chain *Chain) string
- func (content Content) IsEmpty() bool
- func (content Content) MarshalJSON() ([]byte, error)
- func (content *Content) Set(lang Lang, value string)
- func (content *Content) UnmarshalJSON(b []byte) error
- type Lang
Constants ¶
Variables ¶
Functions ¶
func NativeName ¶
Types ¶
type Chain ¶ added in v1.103.0
type Chain struct {
// contains filtered or unexported fields
}
Chain helps configuring the chain of fallbacks for a project.
func NewChain ¶ added in v1.103.0
func NewChain(opts ...ChainOption) *Chain
NewChain initializes a new chain.
type ChainOption ¶ added in v1.103.0
type ChainOption func(chain *Chain)
ChainOption configures the chain when creating a new one.
func WithFallbacks ¶ added in v1.103.0
func WithFallbacks(langs ...Lang) ChainOption
WithFallbacks configures the fallbacks languages of the chain if the requested one is not available. Multiple languages can be specified and the order of declaration will be the priority.
type Content ¶ added in v1.103.0
type Content struct {
// contains filtered or unexported fields
}
Content represents a translatable string that can store a different value in each language.
It can be serialized to JSON to send it to a client application. It can also be used with libs.altipla.consulting/rdb.
func EmptyContent ¶ added in v1.103.0
func EmptyContent() Content
EmptyContent returns an empty content without any values.
func NewContent ¶ added in v1.103.0
NewContent builds a new content with a single translated value.
func NewContentFromMap ¶ added in v1.103.0
NewContentFromMap builds a new content from a map containing one or multiple values.
func (*Content) ClearAll ¶ added in v1.103.0
func (content *Content) ClearAll()
ClearAll removes all translated values in all languages.
func (Content) Get ¶ added in v1.103.0
Get returns the translated value for a language or empty if not present.
func (Content) GetChain ¶ added in v1.103.0
GetChain does the following steps: 1. Return the content in the requested lang if available. 2. Use the fallback languages if one of them is available. Order is important here. 3. Return any lang available randomly to have something.
If the content is empty it returns an empty string.
func (Content) IsEmpty ¶ added in v1.103.0
IsEmpty returns if the content does not contains any translated value in any language.
func (Content) MarshalJSON ¶ added in v1.103.0
MarshalJSON implements the JSON interface.
func (*Content) Set ¶ added in v1.103.0
Set changes the translated value of a language. If empty that language will be discarded from the content.
func (*Content) UnmarshalJSON ¶ added in v1.103.0
UnmarshalJSON implements the JSON interface.