Documentation ¶
Overview ¶
Package langs contains translation helpers.
Index ¶
- Variables
- func IsValid(lang string) bool
- func NativeName(lang Lang) stringdeprecated
- type Chain
- type Content
- func (content *Content) Clear(lang Lang)
- func (content *Content) ClearAll()
- func (content Content) Get(lang Lang) string
- func (content Content) GetChain(chain Chain, lang Lang) string
- func (content Content) IsEmpty() bool
- func (content Content) Map() map[Lang]string
- func (content Content) MarshalJSON() ([]byte, error)
- func (content Content) PlainMap() map[string]string
- func (content *Content) Scan(value interface{}) error
- func (content *Content) Set(lang Lang, value string)
- func (content *Content) UnmarshalJSON(b []byte) error
- func (content Content) Value() (driver.Value, error)
- type Lang
- func (l Lang) Empty() bool
- func (lang Lang) MarshalJSON() ([]byte, error)
- func (lang Lang) MarshalText() ([]byte, error)
- func (lang *Lang) Scan(src any) error
- func (lang Lang) String() string
- func (lang *Lang) UnmarshalJSON(b []byte) error
- func (lang *Lang) UnmarshalText(text []byte) error
- func (lang Lang) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var ( CA = Lang{Code: "ca", Native: "Català", Group: "ca"} DE = Lang{Code: "de", Native: "Deutsch", Group: "de"} DeDE = Lang{Code: "de-DE", Native: "Deutsch", Group: "de"} EN = Lang{Code: "en", Native: "English", Group: "en"} EnGB = Lang{Code: "en-GB", Native: "English", Group: "en"} EnUS = Lang{Code: "en-US", Native: "English", Group: "en"} ES = Lang{Code: "es", Native: "Español", Group: "es"} EsES = Lang{Code: "es-ES", Native: "Español", Group: "es"} EU = Lang{Code: "eu", Native: "Euskera", Group: "eu"} FR = Lang{Code: "fr", Native: "Français", Group: "fr"} FrFR = Lang{Code: "fr-FR", Native: "Français", Group: "fr"} IT = Lang{Code: "it", Native: "Italiano", Group: "it"} JA = Lang{Code: "ja", Native: "日本語", Group: "ja"} PT = Lang{Code: "pt", Native: "Portugues", Group: "pt"} PtPT = Lang{Code: "pt-PT", Native: "Portugues", Group: "pt"} RU = Lang{Code: "ru", Native: "Русский", Group: "ru"} Empty = Lang{} )
var All = []Lang{ CA, DE, DeDE, EN, EnGB, EnUS, ES, EsES, EU, FR, FrFR, IT, JA, PT, PtPT, RU, }
All contains all the known languages of this library.
Functions ¶
func NativeName
deprecated
added in
v0.2.0
Types ¶
type Chain ¶ added in v0.3.0
type Chain struct {
// contains filtered or unexported fields
}
Chain helps configuring the chain of fallbacks for a project.
type Content ¶ added in v0.3.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 NewContent ¶ added in v0.3.0
func NewContent() Content
NewContent returns an empty content without any values.
func NewContentFromMap ¶ added in v0.3.0
NewContentFromMap builds a new content from a map containing one or multiple values.
func NewContentValue ¶ added in v0.3.0
NewContentValue builds a new content with a single translated value.
func ParseContent ¶ added in v0.3.0
ParseContent reads a new content map parsing every language name to check if it's correct. It only returns an error for invalid languages.
func (*Content) ClearAll ¶ added in v0.3.0
func (content *Content) ClearAll()
ClearAll removes all translated values in all languages.
func (Content) Get ¶ added in v0.3.0
Get returns the translated value for a language or empty if not present.
func (Content) GetChain ¶ added in v0.3.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 v0.3.0
IsEmpty returns if the content does not contains any translated value in any language.
func (Content) Map ¶ added in v0.4.0
Map returns a map of every language of the content and its value.
func (Content) MarshalJSON ¶ added in v0.3.0
MarshalJSON implements the JSON interface.
func (Content) PlainMap ¶ added in v0.4.0
PlainMap returns a map of every language of the content and its value in a format that can be serialized to protobufs.
func (*Content) Set ¶ added in v0.3.0
Set changes the translated value of a language. If empty that language will be discarded from the content.
func (*Content) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON implements the JSON interface.
type Lang ¶ added in v0.3.0
Lang represents a language