i18n

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package i18n provides tanGO's small text-translation primitives.

It is intentionally an override layer: callers keep English fallback text inline in source, while registered catalogs provide translated replacements for stable symbolic keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLocaleResolver

func DefaultLocaleResolver(r *http.Request) string

DefaultLocaleResolver resolves the request locale from Accept-Language, using the registered catalogs as the set of supported locales.

func Locale

func Locale(ctx context.Context) string

Locale returns the resolved locale carried by ctx, or "" when none is set.

func Middleware

func Middleware(resolver LocaleResolver) tango.Middleware

Middleware stores the locale resolved for each request on the request's context so later T calls can observe it. A nil resolver uses DefaultLocaleResolver.

func RegisterCatalog

func RegisterCatalog(locale string, catalog map[string]string)

RegisterCatalog merges catalog into the existing catalog for locale. Registering the same key again replaces that key's previous value; other keys and other locales are left untouched.

func T

func T(ctx context.Context, key, fallback string, args ...any) string

T returns the translated string for key using the locale carried by ctx, falling back to fallback when no locale/catalog/key is available. When args are present, the chosen string is formatted with fmt.Sprintf before being returned.

func WithLocale

func WithLocale(ctx context.Context, locale string) context.Context

WithLocale returns a child context carrying locale as the resolved locale for translation lookups.

Types

type LocaleResolver

type LocaleResolver func(*http.Request) string

LocaleResolver resolves the active locale for one incoming request.

Jump to

Keyboard shortcuts

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