localization

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Global = New()

Global is the default localization instance.

Functions

func G

func G(key string, defaults ...string) string

G returns the translation for the given key in the default localization instance.

func GetCurrent

func GetCurrent() string

GetCurrent returns the current locale in the default localization instance.

func SetCurrent

func SetCurrent(locale string)

SetCurrent sets the current locale in the default localization instance.

Types

type Localization

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

func New

func New() *Localization

func (*Localization) Add

func (l *Localization) Add(locale string, translations map[string]string)

Add adds a new locale with the given translations. If the locale already exists, the translations will be added to the existing ones.

func (*Localization) AddFile

func (l *Localization) AddFile(file string) error

AddFile adds a new locale with the given translations from the given file.

func (*Localization) AddFolder

func (l *Localization) AddFolder(folder string) error

AddFolder adds all locales from the given folder. Will walk through all sub-folders and add all .yaml and .yml files.

func (*Localization) G

func (l *Localization) G(key string, defaults ...string) string

G is a shortcut for Get with the current locale.

func (*Localization) Get

func (l *Localization) Get(locale, key string, defaults ...string) string

Get returns the translation for the given key in the given locale. If the key is not found, it will fall back to the "en" locale and if the key is not found there, it will return the key or the given defaults.

func (*Localization) GetCurrent

func (l *Localization) GetCurrent() string

GetCurrent returns the current locale.

func (*Localization) GetLocales

func (l *Localization) GetLocales() []string

GetLocales returns a list of all available locales.

func (*Localization) SetCurrent

func (l *Localization) SetCurrent(locale string)

SetCurrent sets the current locale.

Jump to

Keyboard shortcuts

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