i18n

package
v0.0.0-...-f2087ef Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LocaleHandler

func LocaleHandler(lg *logging.Logger) gin.HandlerFunc

LocaleHandler detect locale from http header

func Migrate

func Migrate(db *gorm.DB)

Migrate migrate database

Types

type GormStore

type GormStore struct {
	Db     *gorm.DB        `inject:""`
	Logger *logging.Logger `inject:""`
}

GormStore db provider

func (*GormStore) Del

func (p *GormStore) Del(lng string, code string)

Del del locale

func (*GormStore) Get

func (p *GormStore) Get(lng string, code string) string

Get get locale

func (*GormStore) Keys

func (p *GormStore) Keys(lng string) ([]string, error)

Keys list locale keys

func (*GormStore) Set

func (p *GormStore) Set(lng string, code, message string)

Set set locale

type I18n

type I18n struct {
	Store  Store           `inject:""`
	Logger *logging.Logger `inject:""`

	Locales map[string]map[string]string
}

I18n i18n helper

func (*I18n) Exist

func (p *I18n) Exist(lang string) bool

Exist is lang exist?

func (*I18n) Load

func (p *I18n) Load(dir string) error

Load load locales from filesystem

func (*I18n) T

func (p *I18n) T(lang string, code string, args ...interface{}) string

T translate by lang tag

type Locale

type Locale struct {
	ID        uint   `gorm:"primary_key"`
	Lang      string `gorm:"not null;type:varchar(8);index"`
	Code      string `gorm:"not null;index;type:VARCHAR(255)"`
	Message   string `gorm:"not null;type:varchar(800)"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Locale locale model

type Store

type Store interface {
	Set(lang string, code, message string)
	Get(lang string, code string) string
	Del(lang string, code string)
	Keys(lang string) ([]string, error)
}

Store i18n store

Jump to

Keyboard shortcuts

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