locale

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgLocaleSetAppLangugeInterface = "LocaleSetAppLangugeInterface"
)

Variables

View Source
var T = func(messageID string, template interface{}) string {

	if GlobalLocalizer == nil {
		SetLanguage("")
	}

	return GlobalLocalizer.Translate(messageID, template)
}

One of 2 main methods to translate message ID text, using format functionality based on template interface.

View Source
var TP = func(messageID string, template interface{}, pluralCount interface{}) string {

	if GlobalLocalizer == nil {
		SetLanguage("")
	}

	return GlobalLocalizer.TranslatePlural(messageID, template, pluralCount)
}

One of 2 main methods to translate message ID text, using format functionality based on template interface. Extra functionality allow to control plural form behavior.

Functions

func SetLanguage

func SetLanguage(lang string)

SetLanguage set up language globally for application localization.

Types

type Localizer

type Localizer struct {
	sync.Mutex

	Lang string
	// contains filtered or unexported fields
}

Localizer is a stub to get access to *i18n.Localizer. As it found, *i18n.Localizer is not a thread safe, so sync.Mutex must be used to synchronize calls to object internals.

var GlobalLocalizer *Localizer

GlobalLocalizer is a global variable to translate everything in application

func CreateLocalizer added in v0.3.3

func CreateLocalizer(lang string) *Localizer

CreateLocalizer create localizer object to generate text messages.

func (*Localizer) Translate added in v0.3.3

func (v *Localizer) Translate(messageID string, template interface{}) string

Translate form and output a message based on messageID and template configuration.

func (*Localizer) TranslatePlural added in v0.3.3

func (v *Localizer) TranslatePlural(messageID string, template interface{},
	pluralCount interface{}) string

TranslatePlural form and output a message based on messageID, template and pluralCount configuration.

Jump to

Keyboard shortcuts

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