i18n

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: GPL-3.0 Imports: 11 Imported by: ? 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

Overview

Package i18n provides immutable ICU MessageFormat catalogs and request middleware.

Index

Constants

This section is empty.

Variables

View Source
var ErrMessageNotFound = errors.New("i18n: message not found")

Functions

func Middleware

func Middleware(bundle *Bundle) middleware.Middleware

Middleware selects locale from session, then platform event, then bundle default. Place it after state.SessionMiddleware to enable persisted locale selection.

func SetLocale

func SetLocale(ctx *botctx.Context, locale string) error

SetLocale changes the request locale and persists it when a session is attached.

Types

type Args

type Args map[string]any

type Bundle

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

Bundle is immutable after construction and safe for concurrent translations.

func New

func New(defaultLocale string, catalogs ...Catalog) (*Bundle, error)

func (*Bundle) DefaultLocale

func (b *Bundle) DefaultLocale() string

func (*Bundle) Translate

func (b *Bundle) Translate(locale, key string, args map[string]any) (string, error)

type Catalog

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

func JSON

func JSON(locale string, r io.Reader) (Catalog, error)

JSON reads a flat JSON object whose keys are message IDs and values are ICU patterns.

func Map

func Map(locale string, messages map[string]string) Catalog

Jump to

Keyboard shortcuts

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