lang

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 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 BaseCode

func BaseCode(lang string) string

BaseCode extracts the ISO 639-1 base language code from a locale. OpenAI's transcription API only accepts base codes, not regional variants. Examples: "pt-BR" -> "pt", "zh-CN" -> "zh", "en" -> "en"

func DisplayName

func DisplayName(lang string) string

DisplayName returns a human-readable name for a language code. Lookup order: exact locale match -> base language -> original code. Returns empty string for empty input. Used in the restructuring prompt instruction.

func IsEnglish

func IsEnglish(lang string) bool

IsEnglish returns true if the language code represents English. Used to skip the output language instruction when output is English (since templates are already in English).

func IsFrench

func IsFrench(lang string) bool

IsFrench returns true if the language code represents French.

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"

func Validate

func Validate(lang string) error

Validate checks if the language code is valid. Accepts ISO 639-1 codes (e.g., "en", "fr") or locales with valid base (e.g., "pt-BR", "zh-CN"). Only the base code is validated; regional suffixes are ignored. Returns nil for empty string (auto-detect mode). Returns ErrInvalid if the base language is not recognized.

Types

This section is empty.

Jump to

Keyboard shortcuts

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