localization

package module
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package localization provides go-i18n middleware for HTTP services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLocalizer

func GetLocalizer(ctx context.Context) *i18n.Localizer

GetLocalizer returns the *i18n.Localizer stored by Middleware, or nil if not set.

func Localize

func Localize(ctx context.Context, cfg *i18n.LocalizeConfig) string

Localize translates cfg using the Localizer from ctx (set by Middleware). If no localizer is in the context or the message is not found, returns cfg.DefaultMessage.Other, or "" if DefaultMessage is nil.

func Middleware

func Middleware(bundle *i18n.Bundle, opts ...Option) func(http.Handler) http.Handler

Middleware selects a locale from the request (priority: cookie -> query param -> Accept-Language), builds an *i18n.Localizer from bundle, and stores it in the context. Use GetLocalizer or Localize to retrieve translations in handlers. bundle must not be nil.

Types

type Option

type Option func(*config)

Option configures the localization middleware.

func WithLanguageCookie

func WithLanguageCookie(name string) Option

WithLanguageCookie sets a cookie name (e.g. "lang") used as language preference, checked first.

func WithLanguageQueryParam

func WithLanguageQueryParam(param string) Option

WithLanguageQueryParam sets a URL query parameter name (e.g. "lang") used as language preference, checked after cookie but before Accept-Language header.

Jump to

Keyboard shortcuts

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