lang

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid language code")

ErrInvalid indicates an invalid language code was specified.

Functions

func Normalize

func Normalize(lang string) string

Normalize normalizes a language code to lowercase with hyphen separator. Converts underscores to hyphens and lowercases the entire string. Does not trim whitespace or validate format. Examples: "pt-BR" -> "pt-br", "pt_BR" -> "pt-br", "PT-BR" -> "pt-br"

Types

type Language

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

Language represents a validated ISO 639-1 language code. The zero value represents "auto-detect" mode and is valid. Use Parse to create a Language from user input.

func MustParse

func MustParse(s string) Language

MustParse parses a language code and panics if invalid. Use only for compile-time constants and tests.

func Parse

func Parse(s string) (Language, error)

Parse validates and returns a Language from a string. Empty string represents "auto-detect" mode and returns a zero Language. Returns ErrInvalid if the language code is not recognized.

func (Language) BaseCode

func (l Language) BaseCode() string

BaseCode returns the ISO 639-1 base code (without region). Returns empty string for auto-detect mode.

func (Language) DisplayName

func (l Language) DisplayName() string

DisplayName returns a human-readable name for this language. Returns empty string for auto-detect mode.

func (Language) IsEnglish

func (l Language) IsEnglish() bool

IsEnglish returns true if this language is English.

func (Language) IsFrench

func (l Language) IsFrench() bool

IsFrench returns true if this language is French.

func (Language) IsZero

func (l Language) IsZero() bool

IsZero returns true if this is the zero value (auto-detect mode). Unlike Provider.IsZero() which indicates an invalid state, Language.IsZero() represents a valid "auto-detect" mode where the API will automatically detect the language.

func (Language) String

func (l Language) String() string

String returns the normalized language code, or empty string for auto-detect.

Jump to

Keyboard shortcuts

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