lang

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package lang provides i18n registries, translators, and message loading.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Provider

func Provider(options ...Option) runaprovider.Provider

Provider registers the language registry.

func Replace

func Replace(message string, params core.Map) string

Replace replaces {key} placeholders with params.

func WithTranslator

func WithTranslator(ctx context.Context, translator *Translator) context.Context

WithTranslator stores a translator in a context.

Types

type Option

type Option func(*optionConfig)

Option configures the language registry.

func DefaultLocale

func DefaultLocale(locale string) Option

DefaultLocale sets the fallback locale.

type Registry

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

Registry stores translations and creates request-scoped translators.

func Default

func Default() *Registry

Default returns the default app language registry.

func New

func New(options ...Option) *Registry

New creates an i18n registry.

func (*Registry) LoadDir

func (registry *Registry) LoadDir(dir string) error

LoadDir loads message files from a directory.

func (*Registry) LoadFile

func (registry *Registry) LoadFile(path string) error

LoadFile loads a TOML or JSON message file.

func (*Registry) Match

func (registry *Registry) Match(values ...string) string

Match returns the best matching locale for language preferences.

func (*Registry) T

func (registry *Registry) T(key string, params ...any) string

T translates a key using the registry default locale.

func (*Registry) Translator

func (registry *Registry) Translator(values ...string) *Translator

Translator creates a translator for locale preferences.

type Translator

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

Translator translates message keys.

func From

func From(ctx context.Context) *Translator

From reads a translator from context or returns the default translator.

func NewTranslator

func NewTranslator(locales ...string) *Translator

NewTranslator creates a fallback translator without a registry.

func (*Translator) Locale

func (translator *Translator) Locale() string

Locale returns the translator locale hint.

func (*Translator) T

func (translator *Translator) T(key string, params ...any) string

T translates a message key.

Jump to

Keyboard shortcuts

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