elrond

package module
v0.0.0-...-b3879e2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2018 License: MIT Imports: 3 Imported by: 0

README

Elrond

i18n translation library

Build Status GoDoc GoReport Development Status

QuickStart

import "github.com/bearyinnovative/elrond"
import "github.com/bearyinnovative/elrond/json"

func Translation() {
	t := elrond.T(
		erlond.C(elrond.EnUS, "Hello, world!"),
		elrond.C(elrond.ZhCN, "你好,世界!"))

	{
		c, ok := t.Content(elrond.EnUS)
		println(c)
		// output: Hello, world

	}
	{
		c, ok := t.Content(elrond.ZhCN)
		println(c)
		// output: 你好,世界!
	}
}

func Bundle() {
	b := elrond.NewBundle()
	b.Add("foo", elrond.T(
		erlond.C(elrond.EnUS, "Hello, world!"),
		elrond.C(elrond.ZhCN, "你好,世界!")))

	c, ok := b.MustGet("foo").Content(elrond.EnUS)
	println(c)
	// output: Hello, world
}

func FromJSON() {
	datas := []byte(`[{"id": "bar", "contents": [{"language": "Zh-CN", "text": "bar"}]}, {"id": "bar", "contents": [{"language": "En-US", "text": "foo"}, {"language": "Zh-CN", "text": "bar"}]}]`)

	bundle, err := json.From(d)

	if err != nil {
		panic(err)
	}

	c, ok := bundle.MustGet("foo").Content(elrond.ZhCN)
	println(c)
	// output: bar
}

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

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

Bundle bundle translations

func NewBundle

func NewBundle() *Bundle

func (*Bundle) Add

func (b *Bundle) Add(id string, t *Translation)

Add translation to bundle

func (*Bundle) Get

func (b *Bundle) Get(id string) (translation *Translation, found bool)

Get translation by id

func (*Bundle) MustGet

func (b *Bundle) MustGet(id string) *Translation

MustGet translation, if not exists then panic

func (*Bundle) Size

func (b *Bundle) Size() int

type Content

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

Content for specified language

func C

func C(language Language, text string) *Content

C create a content, content is empty plain text by default

func (*Content) Language

func (c *Content) Language() Language

Language of content

func (*Content) Parse

func (c *Content) Parse(v interface{}) (string, error)

Parse template

func (*Content) Template

func (c *Content) Template() *template.Template

Template get content raw template

func (*Content) Text

func (c *Content) Text() (string, error)

Text get plain text

type Language

type Language string
const (
	// ZhCN Chinese for China Mainland
	ZhCN Language = "Zh-CN"
	// EnUS English
	EnUS = "En-US"
)

type Translation

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

Translation represents a content for some language.

func T

func T(contents ...*Content) *Translation

T create a new Translation

func (*Translation) Content

func (t *Translation) Content(lang Language) (content *Content, ok bool)

Content get content by language

func (*Translation) Languages

func (t *Translation) Languages() []Language

Languages list all languages of the translation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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