i18n

package
v0.56.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolve

func Resolve(env, configured string, sys func() string) (lang Language, setting Setting, source string, err error)

Resolve applies environment, configuration and system-locale precedence.

func SystemLocale

func SystemLocale() string

SystemLocale returns the raw locale used by auto resolution.

Types

type Catalog

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

Catalog is an initialized, immutable language catalog.

func New

func New(lang Language) (*Catalog, error)

New creates an independent catalog backed by embedded resources.

func NewWithLogger

func NewWithLogger(lang Language, warn WarningFunc) (catalog *Catalog, err error)

NewWithLogger creates a catalog and sends missing-key diagnostics to warn. A nil callback uses the project's slog logger rather than writing to stderr.

func (*Catalog) T

func (c *Catalog) T(key string, args ...map[string]any) string

T translates key with named {placeholders}; literal backslash-n is a newline.

type Language

type Language string

Language is a supported user-interface language.

const (
	LanguageZH Language = "zh"
	LanguageEN Language = "en"
)

type Setting

type Setting string

Setting is the configured language selection mode.

const (
	SettingAuto Setting = "auto"
	SettingZH   Setting = "zh"
	SettingEN   Setting = "en"
)

func NormalizeSetting

func NormalizeSetting(s string) (Setting, error)

NormalizeSetting canonicalizes a language setting or returns an error listing the three values that can be persisted in configuration.

type Translator

type Translator interface {
	T(key string, args ...map[string]any) string
}

Translator is the read-only UI translation surface passed to host renderers.

func Fallback

func Fallback() Translator

Fallback returns the legacy Chinese catalog for components that have not yet been wired with the startup-resolved translator. Real process assembly must always inject the resolved catalog instead.

type WarningFunc

type WarningFunc func(message string)

WarningFunc receives a missing-catalog-key diagnostic.

Jump to

Keyboard shortcuts

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