content

package
v1.57.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package content has models for translated content coming from multiple providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LangChain

func LangChain(translations map[string]string, lang string) string

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

type Provider map[string]string

func (Provider) Chain

func (content Provider) Chain() string

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

func (content Provider) ChainProvider() string

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

func (content Provider) CustomChain(chain []string) string

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

func (content Provider) CustomChainProvider(chain []string) string

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.

func (*Provider) Scan

func (content *Provider) Scan(value interface{}) error

func (Provider) Value

func (content Provider) Value() (driver.Value, error)

type Translated

type Translated map[string]string

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

func (Translated) Value

func (content Translated) Value() (driver.Value, 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.

func (TranslatedProvider) Value

func (content TranslatedProvider) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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