localization

package
v0.0.0-...-d814896 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I18n

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

I18n implements the Localizer interface

func (*I18n) AddLocale

func (l *I18n) AddLocale(localeKey string, translations map[string]string)

AddLocale Adds a locale to the localizer

func (*I18n) LoadJSONLocalesFromFolder

func (l *I18n) LoadJSONLocalesFromFolder(localesPath string) error

LoadJSONLocalesFromFolder Parses and Loads all the locales in json format in a folder (filename is used as the key of the locale. Ex: en.json -> "en", de.json -> "de")

func (*I18n) Translator

func (l *I18n) Translator(localeKey string) Translator

Translator Returns a translator for the locale. If no locale is added, it returns an empty translator

type I18nTranslator

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

I18nTranslator implements the Translator interface

func (*I18nTranslator) Tr

func (t *I18nTranslator) Tr(key string, args ...interface{}) string

Tr Translates a key. Format the string using additional parameters

type Localizer

type Localizer interface {
	AddLocale(localeKey string, translations map[string]string)
	Translator(localeKey string) Translator
	LoadJSONLocalesFromFolder(localesPath string) error
}

Localizer defines the interface for a localizer

func Get

func Get() Localizer

Get returns a singleton localizer if you need a plug and play option We dont need a thread safe singleton in most cases as we dont change any data once loaded. So it is not thread safe

func NewLocalizer

func NewLocalizer() Localizer

NewLocalizer Returns a new localizer which carries translations from the given locale path

type Translator

type Translator interface {
	Tr(key string, args ...interface{}) string
}

Translator defines the interface for a translator

Jump to

Keyboard shortcuts

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