i18n

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActiveLang string

ActiveLang is the resolved active language tag. Set once in rootCmd.PersistentPreRunE before any command body runs.

Functions

func Lookup

func Lookup(lang, key string) (string, bool)

Lookup returns the translation for key in lang (falling back to en). Returns the string and true if found in either catalog; "", false if absent from both.

func Resolve

func Resolve(cfgLang string) string

Resolve returns the active language tag. Priority: cfgLang (if non-empty, used exclusively) → LANG env var → LC_ALL env var → "en". Empty env var values are treated as unset. All inputs are stripped of region/encoding suffixes: "de_AT.UTF-8" → "de". Unknown tags (no catalog) resolve to "en".

func T

func T(lang, key string) string

T returns the translation for key, falling back to the raw key string if not found.

func Tf

func Tf(lang, key string, data map[string]any) string

Tf resolves key via T and executes it as a text/template with data. Uses missingkey=error: missing keys in data trigger a failure. On any parse or execute failure, returns the raw (un-executed) catalog string. If data is nil, template actions will fail (missingkey=error), returning the raw string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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