translator

package
v3.0.7 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package translator provides internationalization support for validation messages.

The translator package enables localization of validation error messages, allowing applications to provide user-friendly error messages in different languages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultEnglishTranslations

func DefaultEnglishTranslations() map[string]string

DefaultEnglishTranslations returns a map of default English messages.

Returns:

  • map[string]string: A map containing default English error messages for validation failures.

func MergeTranslations added in v3.0.5

func MergeTranslations(base map[string]string, overlays ...map[string]string) map[string]string

MergeTranslations returns a new map with later maps overriding earlier maps.

func RegisterDefaultEnglishTranslations added in v3.0.5

func RegisterDefaultEnglishTranslations(messages map[string]string)

RegisterDefaultEnglishTranslations adds process-wide default English translations. Plugin packages call this from init.

Types

type SimpleTranslator

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

SimpleTranslator is a basic implementation of Translator using a map.

Fields:

  • messages: Map of message keys to localized strings.

func NewSimpleTranslator

func NewSimpleTranslator(messages map[string]string) *SimpleTranslator

NewSimpleTranslator creates a new SimpleTranslator.

Parameters:

  • messages: Map of message keys to localized strings.

Returns:

  • *SimpleTranslator: A new SimpleTranslator instance.

func (*SimpleTranslator) T

func (st *SimpleTranslator) T(key string, params ...any) string

T returns the translated message or the default if not found.

Parameters:

  • key: The message key to look up.
  • params: Variable number of parameters for message formatting.

Returns:

  • string: The localized message or the key as fallback.

type Translator

type Translator interface {
	// T returns a localized message for the given key and parameters.
	T(key string, params ...any) string
}

Translator is an interface for obtaining localized messages.

This interface provides a way to get localized error messages for validation failures.

Jump to

Keyboard shortcuts

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