locale

package
v0.0.0-...-bedf5c0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MPL-2.0 Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Day  = 24 * time.Hour
	Week = 7 * Day
	Year = 365 * Day
)

Variables

This section is empty.

Functions

func Current

func Current() *gotext.Locale

Current returns the current locale.

func Get

func Get(str string, vars ...any) string

Get returns the translated string from the given reference.

func GetFromDomain

func GetFromDomain(domain, str string, vars ...any) string

GetFromDomain returns the translated string from the given reference and domain. Use this if your string is in a different domain.

func LoadCustomLocale

func LoadCustomLocale(locale string, localeFS fs.FS)

LoadCustomLocale loads the locale from the given filesystem.

func LoadLocale

func LoadLocale(defaultLocaleDomain fs.FS)

LoadLocale loads the locale from the given filesystem. It will try to find the best match for the current locale.

func RegisterLocaleDomain

func RegisterLocaleDomain(domain string, fs fs.FS)

RegisterLocaleDomain registers a locale domain. This is used to load translations from a different domain.

func Sprintf

func Sprintf(str string, vars ...any) string

Sprintf is an alias for Get.

func Time

func Time(t time.Time, long bool) string

Time formats the given timestamp as a locale-compatible timestamp.

func TimeAgo

func TimeAgo(timestamp time.Time) string

TimeAgo formats a long string that expresses the relative time difference from now until t.

Types

type Localized

type Localized string

Localized is a string that can be localized. Its String() method will return the localized string.

func (Localized) GoString

func (l Localized) GoString() string

func (Localized) String

func (l Localized) String() string

String implements fmt.Stringer. It returns the localized string.

Jump to

Keyboard shortcuts

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