langs

package
v1.103.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package langs contains the full list of abreviations of locales available to the system.

Index

Constants

View Source
const (
	CA = Lang("ca")
	DE = Lang("de")
	EN = Lang("en")
	ES = Lang("es")
	EU = Lang("eu")
	FR = Lang("fr")
	IT = Lang("it")
	JA = Lang("ja")
	PT = Lang("pt")
	RU = Lang("ru")
)

Variables

View Source
var All = []Lang{
	CA,
	DE,
	EN,
	ES,
	EU,
	FR,
	IT,
	JA,
	PT,
	RU,
}

Functions

func IsValid

func IsValid(lang string) bool

func NativeName

func NativeName(lang Lang) string

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

func NewContent(lang Lang, value string) Content

NewContent builds a new content with a single translated value.

func NewContentFromMap added in v1.103.0

func NewContentFromMap(values map[Lang]string) Content

NewContentFromMap builds a new content from a map containing one or multiple values.

func (*Content) Clear added in v1.103.0

func (content *Content) Clear(lang Lang)

Clear removes a specific language translated value.

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

func (content Content) Get(lang Lang) string

Get returns the translated value for a language or empty if not present.

func (Content) GetChain added in v1.103.0

func (content Content) GetChain(lang Lang, chain *Chain) string

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

func (content Content) IsEmpty() bool

IsEmpty returns if the content does not contains any translated value in any language.

func (Content) MarshalJSON added in v1.103.0

func (content Content) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON interface.

func (*Content) Set added in v1.103.0

func (content *Content) Set(lang Lang, value string)

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

func (content *Content) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the JSON interface.

type Lang added in v1.103.0

type Lang string

func (Lang) String added in v1.103.0

func (lang Lang) String() string

Jump to

Keyboard shortcuts

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