i18n

package
v0.9.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultLanguage  = "zh-hans"
	InstanceLanguage = "en"
)
View Source
const AcceptHeader = "Accept-Language"

Variables

This section is empty.

Functions

func LanguageFrom

func LanguageFrom(ctx context.Context) string

LanguageFrom is empty for a request that never met the negotiator, which Localizer already reads as the default language.

func Normalize

func Normalize(lang string) string

func WithLanguage

func WithLanguage(ctx context.Context, lang string) context.Context

Types

type Bundle

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

func Load

func Load(overrideDir string) (*Bundle, error)

func LoadKeys

func LoadKeys() (*Bundle, error)

Goldens rendered with this bundle pin which message lands where without pinning its wording, so a rewording does not force every golden to be redone.

func (*Bundle) Choices

func (b *Bundle) Choices() []Choice

func (*Bundle) For

func (b *Bundle) For(ctx context.Context) *Localizer

func (*Bundle) Has

func (b *Bundle) Has(lang string) bool

func (*Bundle) Instance

func (b *Bundle) Instance() string

func (*Bundle) Languages

func (b *Bundle) Languages() []string

func (*Bundle) Localizer

func (b *Bundle) Localizer(lang string) *Localizer

func (*Bundle) Match

func (b *Bundle) Match(accept string) string

Match is empty when the header names nothing the bundle carries, so the caller can tell "no opinion" apart from "asked for the default".

func (*Bundle) Name

func (b *Bundle) Name(lang string) string

A catalog names its own language, so adding one is a JSON file and nothing else.

func (*Bundle) Negotiate

func (b *Bundle) Negotiate(chosen, accept, siteDefault string) string

A chosen language outranks the browser's, because a browser speaks for a device and a member speaks for themselves.

type Choice

type Choice struct {
	Tag  string
	Name string
}

type Localizer

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

func (*Localizer) Lang

func (l *Localizer) Lang() string

func (*Localizer) T

func (l *Localizer) T(id string, args ...any) string

Jump to

Keyboard shortcuts

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