ui

package
v0.0.0-...-724bf7d Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 1 Imported by: 0

README

UI 用户接口模块

用于处理与用户输入输出相关的内容

翻译信息 Messages 对象

翻译消息集合 Collection 对象

待翻译语言 Language 对象

标签及标签集合 Label Labels 对象

可翻译信息 Message 对象

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTranslations = NewTranslations()

DefaultTranslations default messages Translations

View Source
var Lang = ""

Lang default langauge used by Translate func.

Functions

func Get

func Get(module string, key string) string

Get translate messsage by default langauge ,given module and ky.

func GetIn

func GetIn(lang string, module string, key string) string

GetIn translate messsage by given langauge module and ky.

func Replace

func Replace(str string, m map[string]string) string

Replace replace string with given replace mapper. Words begin with {{ and end with }} will be replace with mappedvalue Use "\{" , "\}" , "\\" to keep "{" , "}" "\" char.

Types

type Collection

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

Collection struct which hold avaliable message map and translated messages.

func NewCollection

func NewCollection(messages *Messages, messagesmap map[string]string) *Collection

NewCollection create new map with given avaliable map and translated messages.

func (*Collection) GetLabel

func (m *Collection) GetLabel(field string) string

GetLabel get translated field label .

type Component

type Component interface {
	ComponentID() string
}

Component basic ui component

type ComponentLabels

type ComponentLabels interface {
	GetComponentLabels() Labels
	SetComponentLabels(Labels)
	GetLabel(string) string
}

ComponentLabels ui component with labels

type Label

type Label interface {
	Label() string
}

Label label interface

type Labels

type Labels interface {
	GetLabel(string) string
}

Labels labels interface

type LabelsComponent

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

LabelsComponent component struct with labels

func (*LabelsComponent) ComponentID

func (c *LabelsComponent) ComponentID() string

ComponentID return component id

func (*LabelsComponent) GetComponentLabels

func (c *LabelsComponent) GetComponentLabels() Labels

GetComponentLabels get labels from component

func (*LabelsComponent) GetLabel

func (c *LabelsComponent) GetLabel(field string) string

GetLabel get label from componet labels

func (*LabelsComponent) SetComponentLabels

func (c *LabelsComponent) SetComponentLabels(labels Labels)

SetComponentLabels get labels from component

type Language

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

Language translation language struct

func (*Language) Lang

func (l *Language) Lang() string

Lang get language

func (*Language) SetLang

func (l *Language) SetLang(lang string)

SetLang set language

type MapLabels

type MapLabels map[string]string

MapLabels kabels collection in map form

func (MapLabels) GetLabel

func (l MapLabels) GetLabel(field string) string

GetLabel get field label by field name

type Message

type Message struct {
	Module string
	Text   string
}

Message message which should be translated

func NewMessage

func NewMessage(module string, message string) *Message

NewMessage create new message with given module and text.

func (*Message) Translate

func (m *Message) Translate(lang string) string

Translate translate message with default translations. if lang if empty,Lang will be used.

func (*Message) TranslateWith

func (m *Message) TranslateWith(t *Translations, lang string) string

TranslateWith translate message with given translations and language

func (*Message) Translated

func (m *Message) Translated(lang string) *Translated

Translated create translated message by given language

type Messages

type Messages map[string]string

Messages translate messages map.

func GetMessages

func GetMessages(lang string, module string) *Messages

GetMessages by given lang and modules Default Lang will used if lang is empty

func NewMessages

func NewMessages() *Messages

NewMessages create new messages

func (*Messages) Collection

func (m *Messages) Collection(messagesmap map[string]string) *Collection

Collection create collection with given messagesmap

func (*Messages) Get

func (m *Messages) Get(key string) string

Get get translated string for key. Return key if translateed string not exist.

func (*Messages) Load

func (m *Messages) Load(key string) (string, bool)

Load check if translated string exists for given key. If string exists,return tranlasted string and true. If string does not exist,return key and false.

func (*Messages) Set

func (m *Messages) Set(key string, message string) *Messages

Set set translated string to key. Return messages self.

type StringLabel

type StringLabel string

StringLabel string label

func (StringLabel) Label

func (l StringLabel) Label() string

Label label string

type TemplateMessage

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

TemplateMessage message with template

func NewTemplateMessage

func NewTemplateMessage(module string, message string, tokens map[string]string) *TemplateMessage

NewTemplateMessage create new message with given module and text.

func (*TemplateMessage) Translate

func (m *TemplateMessage) Translate(lang string) string

Translate translate message with default translations. if lang if empty,Lang will be used.

func (*TemplateMessage) TranslateWith

func (m *TemplateMessage) TranslateWith(t *Translations, lang string) string

TranslateWith translate message with given translations and language

func (*TemplateMessage) Translated

func (m *TemplateMessage) Translated(lang string) *Translated

Translated create translated message by given language

type Translatable

type Translatable interface {
	Translate(lang string) string
}

Translatable interface which can be translated

type Translated

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

Translated translated message

func NewTranslated

func NewTranslated(translateable Translatable, lang string) *Translated

NewTranslated create new translated message

func (*Translated) Label

func (t *Translated) Label() string

Label return translated string

type TranslationLanguage

type TranslationLanguage interface {
	Lang() string
	SetLang(string)
}

TranslationLanguage translateable interface

type Translations

type Translations map[string]map[string]*Messages

Translations messages collection grouped by lang and module.

func NewTranslations

func NewTranslations() *Translations

NewTranslations create new messages Translations

func (*Translations) Get

func (c *Translations) Get(lang string, module string, key string) string

Get load get message by given lang,module and key. Return translated message if found. Return raw message if not found

func (*Translations) GetMessages

func (c *Translations) GetMessages(lang string, module string) *Messages

GetMessages get messages by given lang and module Return nil if messages not found

func (*Translations) Load

func (c *Translations) Load(lang string, module string, key string) (string, bool)

Load load translated message by given lang.module and key. Return translated message and true if found. Return raw message and false if not found

func (*Translations) SetMessages

func (c *Translations) SetMessages(lang string, module string, m *Messages)

SetMessages set collection messages by given lang and module

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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