Documentation ¶
Overview ¶
Package content has models for translated content coming from multiple providers.
Index ¶
- func LangChain(translations map[string]string, lang string) string
- func SetGlobalProviderChain(chain []string)
- type Provider
- func (content Provider) Chain() string
- func (content Provider) ChainProvider() string
- func (content Provider) CustomChain(chain []string) string
- func (content Provider) CustomChainProvider(chain []string) string
- func (content *Provider) Scan(value interface{}) error
- func (content Provider) Value() (driver.Value, error)
- type Translated
- type TranslatedProvider
- func (content TranslatedProvider) Chain() Translated
- func (content TranslatedProvider) ChainProvider() Translated
- func (content TranslatedProvider) CustomChain(chain []string) Translated
- func (content TranslatedProvider) CustomChainProvider(chain []string) Translated
- func (content TranslatedProvider) Provider(provider string) Translated
- func (content *TranslatedProvider) Scan(value interface{}) error
- func (content TranslatedProvider) SetValue(provider, lang, value string)
- func (content TranslatedProvider) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LangChain ¶
LangChain returns a value following a prearranged chain of preference.
The chain gives preference to the requested lang, then english and finally spanish if no other translation is available.
func SetGlobalProviderChain ¶
func SetGlobalProviderChain(chain []string)
SetGlobalProviderChain configures the global chain of providers when calling a Provider.Chain() method. It is NOT thread-safe, you should call it at init() when starting the app and it shouldn't change again never.
Types ¶
type Provider ¶
func (Provider) Chain ¶
Chain returns the value of the first provider of the global chain list that has content. If no provider has content it will return an empty string.
func (Provider) ChainProvider ¶
ChainProvider returns the first provider of the global chain list that has content. If no provider has content it will return an empty string.
func (Provider) CustomChain ¶
CustomChain returns the value of the first provider of the chain list that has content. If no chain is provided it returns a random provider. If no provider has content it will return an empty string.
Any provider not in the list won't count the in the chain at all, it will be ignored.
func (Provider) CustomChainProvider ¶
CustomChainProvider returns the first provider of the chain list that has content. If no chain is provided it returns a random provider. If no provider has content it will return an empty string.
Any provider not in the list won't count the in the chain at all, it will be ignored.
type Translated ¶
func (Translated) LangChain ¶
func (content Translated) LangChain(lang string) string
LangChain runs the lang chain over the contents of the container.
func (*Translated) Scan ¶
func (content *Translated) Scan(value interface{}) error
type TranslatedProvider ¶
type TranslatedProvider map[string]Translated
func (TranslatedProvider) Chain ¶
func (content TranslatedProvider) Chain() Translated
Chain returns the value of every language of the first provider of the global chain list that has content.
func (TranslatedProvider) ChainProvider ¶
func (content TranslatedProvider) ChainProvider() Translated
ChainProvider returns the first provider of every language of the global chain list that has content.
func (TranslatedProvider) CustomChain ¶
func (content TranslatedProvider) CustomChain(chain []string) Translated
CustomChain returns the value of every language of the first provider of the chain list that has content. If no chain is provided it returns a random provider.
Any provider not in the list won't count the in the chain at all, it will be ignored.
func (TranslatedProvider) CustomChainProvider ¶
func (content TranslatedProvider) CustomChainProvider(chain []string) Translated
CustomChainProvider returns the first provider of every language of the chain list that has content. If no chain is provided it returns a random provider.
Any provider not in the list won't count the in the chain at all, it will be ignored.
func (TranslatedProvider) Provider ¶
func (content TranslatedProvider) Provider(provider string) Translated
Provider returns a single provider from the data. If the provider is not assigned yet it will return an empty translation instead of the nil of a direct access.
func (*TranslatedProvider) Scan ¶
func (content *TranslatedProvider) Scan(value interface{}) error
func (TranslatedProvider) SetValue ¶
func (content TranslatedProvider) SetValue(provider, lang, value string)
SetValue changes a single value in a single provider. It helps to avoid a nil panic when the provider is not assigned yet.