content

package module
v2.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: MIT Imports: 3 Imported by: 1

README

content

GoDoc

Models for translated content coming from multiple providers.

Install
go get github.com/altipla-consulting/content

This library has no external dependencies outside the Go standard library.

Usage

You can use the types of this package in your models structs when working with database/sql:

type MyModel struct {
  ID          int64      `db:"id,omitempty"`
  Name        content.Translated `db:"name"`
  Description content.Translated `db:"description"`
  Description content.Provider `db:"description"`
}
Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using gofmt.

Running tests

Start the test database:

docker-compose up -d database

Install test libs:

go get github.com/stretchr/testify
go get upper.io/db.v3

Run the tests:

go test

Shutdown the database when finished testing:

docker-compose stop database
License

MIT License

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