loc

package
v0.0.0-...-4f8f121 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: MIT Imports: 1 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context holds a localization context (a combination of a language, a corresponding Plurr formatter, and a link back to parent localization Pool object)

func (*Context) Format

func (lc *Context) Format(key string, params plurr.Params) string

Format returns a formatted version of the string

func (*Context) GetContext

func (lc *Context) GetContext(lang string) *Context

GetContext returns a context for another language within the same localization pool. It can be used to switch languages within the same pool (think of it as of a `SetLanguage()` function which returns a new context without changing the current one).

func (*Context) GetLanguage

func (lc *Context) GetLanguage() string

GetLanguage returns the current language of the context.

func (*Context) Tr

func (lc *Context) Tr(key string) string

Tr returns a translated version of the string

type Pool

type Pool struct {
	DefaultLanguage string
	Resources       map[string]Resources
	// contains filtered or unexported fields
}

Pool object holds all string resources and language-specific contexts. Pool can be created either for an entire project, or for each logical part of the application that has its own set of strings.

func NewPool

func NewPool(defaultLanguage string) *Pool

NewPool creates a new localization pool object

func (*Pool) GetContext

func (lp *Pool) GetContext(lang string) *Context

GetContext returns a translation context based on the provided language. Contexts are thread-safe.

type Resources

type Resources map[string]string

Resources is an array that holds string resources for a particular language

Jump to

Keyboard shortcuts

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