i18n

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package i18n provides internationalization support for the framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(cfg *Config)

Configure initializes the internationalization system with the provided configuration. It sets up the filesystem and base path for locale files, then loads all message catalogs. Panics if locales directory or filesystem is missing.

func ContextWithI18nPrinter

func ContextWithI18nPrinter(ctx context.Context, printer *message.Printer) context.Context

ContextWithI18nPrinter adds the message printer to the context ContextWithI18nPrinter stores a message printer in the context. Returns a new context containing the printer, which can be retrieved later with PrinterFromContext.

func GetI18nPrinter

func GetI18nPrinter(langTag language.Tag) *message.Printer

GetI18nPrinter creates a message printer for the given language tag GetI18nPrinter creates a message printer for the specified language tag. The printer can be used to translate messages according to the loaded message catalogs. Returns a printer configured for the given language tag.

func PrinterFromContext

func PrinterFromContext(ctx context.Context) (*message.Printer, bool)

PrinterFromContext retrieves a message printer from the context. Returns the printer and true if found, or nil and false if not present.

Types

type Config

type Config struct {
	FS                 fs.FS
	SupportedLanguages []language.Tag
}

Config holds i18n configuration.

func Configuration

func Configuration() (Config, bool)

Configuration returns the current i18n configuration. Returns the config and true if i18n is configured, or an empty config and false if not configured.

type MessageEntry

type MessageEntry struct {
	Placeholders map[string]Placeholder `json:"placeholders,omitempty"`
	ID           string                 `json:"id"`
	Message      string                 `json:"message"`
	Translation  string                 `json:"translation,omitempty"`
}

MessageEntry represents a single message with its translations and placeholders.

type MessageFile

type MessageFile struct {
	Language string         `json:"language"`
	Messages []MessageEntry `json:"messages"`
}

MessageFile represents the structure of the JSON message files.

type Placeholder

type Placeholder struct {
	ID             string `json:"id"`
	String         string `json:"string"`
	Type           string `json:"type"`
	UnderlyingType string `json:"underlyingType"`
	Expr           string `json:"expr"`
	ArgNum         int    `json:"argNum"`
}

Placeholder represents a placeholder in a message.

Jump to

Keyboard shortcuts

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