locale

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package locale provides internationalization (i18n) support for the l-ui web panel, including translation loading, localization, and middleware for web and bot interfaces.

Index

Constants

This section is empty.

Variables

View Source
var (
	LocalizerWeb *i18n.Localizer
	LocalizerBot *i18n.Localizer
)

Functions

func I18n

func I18n(i18nType I18nType, key string, params ...string) string

I18n retrieves a localized message for the given key and type. It supports both bot and web contexts, with optional template parameters. Returns the localized message or an empty string if localization fails.

func InitLocalizer

func InitLocalizer(i18nFS embed.FS, settingService SettingService) error

InitLocalizer initializes the internationalization system with embedded translation files.

func LocalizerMiddleware

func LocalizerMiddleware() gin.HandlerFunc

LocalizerMiddleware returns a Gin middleware that sets up localization for web requests. It determines the user's language from cookies or Accept-Language header, creates a localizer instance, and stores it in the Gin context for use in handlers. Also provides the I18n function in the context for template rendering.

Types

type I18nType

type I18nType string

I18nType represents the type of interface for internationalization.

const (
	Bot I18nType = "bot" // Bot interface type
	Web I18nType = "web" // Web interface type
)

type SettingService

type SettingService interface {
	GetTgLang() (string, error)
}

SettingService interface defines methods for accessing locale settings.

Jump to

Keyboard shortcuts

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