localization

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package localization provides internationalization (i18n) support for Omnom.

This package handles translation of user interface strings into multiple languages using the go-i18n library. Translation files are JSON-based and embedded in the application at build time.

Supported features:

  • Multiple language support with automatic fallback to English
  • Parameterized message templates
  • Language detection from Accept-Language headers
  • Embedded translation files

Translation files are stored in the locales/ directory with names like en.json, es.json, etc. Each file contains message IDs and their translated strings.

The Localizer type provides thread-safe translation lookups for a specific language preference. The global SupportedLanguages slice contains metadata about all available translations.

Example usage:

// Create a localizer for a user's preferred languages
loc := localization.NewLocalizer("es", "en")

// Translate a simple message
text := loc.Msg("welcome_message")

// Translate with parameters
text := loc.Msgf("greeting", "name", userName, "count", itemCount)

Index

Constants

This section is empty.

Variables

View Source
var SupportedLanguages []*LangInfo

SupportedLanguages contains all available language translations.

Functions

This section is empty.

Types

type LangInfo

type LangInfo struct {
	Abbr        string
	EnglishName string
	Name        string
}

LangInfo contains information about a language.

type Localizer

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

Localizer provides translation functionality.

func NewLocalizer

func NewLocalizer(langs ...string) *Localizer

NewLocalizer creates a new localizer for the specified languages.

func (*Localizer) Msg

func (l *Localizer) Msg(msg string) string

Msg translates a string

func (*Localizer) Msgf added in v0.7.0

func (l *Localizer) Msgf(msg string, values ...any) string

Msgf translates a string with optional translation settings. See https://pkg.go.dev/github.com/nicksnyder/go-i18n/v2@v2.6.0/i18n#LocalizeConfig for details.

Jump to

Keyboard shortcuts

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