i18n

package
v0.0.0-...-28b3ec9 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 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(c *gin.Context)

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 *language.Tag, code string)

Del del locale

func (*GormStore) Get

func (p *GormStore) Get(lng *language.Tag, code string) string

Get get locale

func (*GormStore) Keys

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

Keys list locale keys

func (*GormStore) Set

func (p *GormStore) Set(lng *language.Tag, 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

func (*I18n) T

func (p *I18n) T(lng *language.Tag, code string, args ...interface{}) string

T translate by lang tag

func (*I18n) Ts

func (p *I18n) Ts(args ...interface{}) string

Ts translate by lang

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 *language.Tag, code, message string)
	Get(lang *language.Tag, code string) string
	Del(lang *language.Tag, code string)
	Keys(lang *language.Tag) ([]string, error)
}

Store i18n store

Jump to

Keyboard shortcuts

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