i18n

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Translator

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

Translator loads and resolves translated messages by locale.

func NewTranslator

func NewTranslator(fallback string) *Translator

NewTranslator returns an empty translator with the given fallback locale.

func (*Translator) Get

func (t *Translator) Get(locale, key string, args ...interface{}) string

Get resolves a translation key for the given locale. If the key is not found in the requested locale, the fallback locale is tried. If still not found, the raw key is returned. When args are provided, the first element is used as template data for text/template interpolation.

func (*Translator) LoadDir

func (t *Translator) LoadDir(dir string) error

LoadDir loads all *.json files from a directory. Each file's name (without extension) is used as the locale.

func (*Translator) LoadFile

func (t *Translator) LoadFile(locale, path string) error

LoadFile reads a JSON translation file and stores it under the given locale.

Jump to

Keyboard shortcuts

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