translator

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: MIT Imports: 1 Imported by: 0

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.

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