i18n

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 24 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

Index

Constants

View Source
const (
	BundledSource = "bundled"
	OverlaySource = "overlay"
)
View Source
const CoreSurface = "core"
View Source
const DefaultLanguage = "en"

Variables

View Source
var BundledLanguageInfo = map[string]bundledLanguage{
	"af": {"Afrikaans", false}, "ar": {"العربية", true}, "de": {"Deutsch", false}, "en": {"English", false},
	"es": {"Español", false}, "fr": {"Français", false}, "ga": {"Gaeilge", false}, "hu": {"Magyar", false},
	"it": {"Italiano", false}, "ja": {"日本語", false}, "ko": {"한국어", false}, "pt": {"Português", false},
	"ru": {"Русский", false}, "tr": {"Türkçe", false}, "uk": {"Українська", false}, "zh": {"简体中文", false},
	"zh-hant": {"繁體中文", false},
}

BundledLanguageInfo maps each bundled id to its endonym and script direction

View Source
var ErrUnscopedSecret = errors.New("secret read with no profile scope while multiplexing")

ErrUnscopedSecret marks a secret read refused because multiplexing is on with no scope bound

View Source
var SupportedLanguages = []string{"en", "zh", "zh-hant", "ja", "de", "es", "fr", "tr", "uk", "af", "ko", "it", "ga", "pt", "ru", "hu", "ar"}

SupportedLanguages are the bundled catalogs

View Source
var Surfaces = []string{CoreSurface, "tui"}

Functions

func ClearLayerCache

func ClearLayerCache()

ClearLayerCache drops merged layer views but keeps the registrations

func Flatten

func Flatten(node any, prefix string, out map[string]string) map[string]string

Flatten turns a nested mapping into dotted keys keeping only text leaves

func GetLanguage

func GetLanguage(ctx context.Context) string

GetLanguage resolves the active language, env over config over the default

func IsLanguageID

func IsLanguageID(value any) bool

IsLanguageID reports whether the normalized value is a language subtag with optional parts

func LanguageSurfaces

func LanguageSurfaces(ctx context.Context, h string) map[string][]string

LanguageSurfaces maps each language to the surfaces some layer has strings for, in Surfaces order

func LayerSurfaceCatalog

func LayerSurfaceCatalog(h, lang, surface string) map[string]string

LayerSurfaceCatalog merges overlay and packs for one surface, packs winning, bundled excluded

func LayeredLanguages

func LayeredLanguages(h string) []string

LayeredLanguages lists languages supplied by the home overlay or any pack

func LoadBundled

func LoadBundled(name string) map[string]string

LoadBundled returns one bundled catalog flattened

func LoadLocaleSource

func LoadLocaleSource(source any) (map[string]string, error)

LoadLocaleSource flattens a mapping source or parses a path source

func NonTextLeaves

func NonTextLeaves(node any, prefix string) []string

NonTextLeaves lists dotted paths of leaves that are neither text nor a mapping

func NormalizeLanguageID

func NormalizeLanguageID(value any) string

NormalizeLanguageID lowercases, trims and swaps underscores for hyphens, empty for non text

func OverlayDir

func OverlayDir(h string) string

OverlayDir is the user overlay directory of a home

func OverlayLanguages

func OverlayLanguages(h string) []string

OverlayLanguages lists languages with at least one overlay file under the home

func OverlayLayer

func OverlayLayer(h, lang, surface string) map[string]string

OverlayLayer reads the home overlay for a language and surface, empty and logged when missing or broken

func PackLanguages

func PackLanguages() []string

PackLanguages lists the languages some pack supplies, sorted

func PackLayer

func PackLayer(lang, surface string) map[string]string

PackLayer merges pack messages for a language and surface in registration order

func ParseLocaleFile

func ParseLocaleFile(path string) (map[string]string, error)

ParseLocaleFile parses one locale YAML file into a flat catalog

func ParseLocaleYAML

func ParseLocaleYAML(name string, data []byte) (map[string]string, error)

ParseLocaleYAML parses locale YAML bytes into a flat catalog, failing on a non mapping document

func PyFormat

func PyFormat(template string, kwargs map[string]any) (string, error)

PyFormat applies Python str.format with keyword arguments only and no positional arguments

func ResetLanguageCache

func ResetLanguageCache()

ResetLanguageCache drops resolved languages, merged catalogs and every layer view

func ResetRegistryForTests

func ResetRegistryForTests()

ResetRegistryForTests drops every pack registration and cached view

func ResolveLanguageID

func ResolveLanguageID(ctx context.Context, value any, h string) string

ResolveLanguageID maps a code, alias or regional tag to a supported id, empty when no layer supplies it

func SetSecretReader

func SetSecretReader(r SecretReader)

SetSecretReader installs the scoped secret resolver the language lookup reads ICEBATH_LANGUAGE through

func SupportedLanguagesFor

func SupportedLanguagesFor(ctx context.Context, h string) []string

SupportedLanguagesFor lists every language a layer supplies for the home, en first then sorted

func SurfaceCatalog

func SurfaceCatalog(ctx context.Context, lang, surface string) map[string]string

SurfaceCatalog is what a renderer receives for one surface, the core surface omitting bundled strings

func T

func T(ctx context.Context, key, lang string, kwargs map[string]any) string

T translates a dotted key into the explicit or active language with English then key fallback

func UnregisterPack

func UnregisterPack(entry *PackEntry) bool

UnregisterPack drops one registration, false when it was already gone

Types

type BundledLocales

type BundledLocales struct {
	FS    fs.FS
	Label string
}

BundledLocales is the bundled locale tree and the path label it is reported under

func LocalesDir

func LocalesDir() BundledLocales

LocalesDir reports the bundled locale tree in effect

type FormatError

type FormatError = pyrepr.FormatError

Python format failure tagged with the exception class it raises

type LanguageOption

type LanguageOption struct {
	ID       string   `json:"id"`
	Endonym  string   `json:"endonym"`
	RTL      bool     `json:"rtl"`
	Source   string   `json:"source"`
	Surfaces []string `json:"surfaces"`
}

LanguageOption is one picker row for a supported language

func DescribeLanguage

func DescribeLanguage(lang string, pack *PackInfo, overlay bool, surfaces []string) LanguageOption

DescribeLanguage builds one picker row, bundled table over pack metadata over the bare id

func LanguageOptions

func LanguageOptions(ctx context.Context) []LanguageOption

LanguageOptions lists every supported language for the current home, en first then sorted by id

type LocaleFile

type LocaleFile struct {
	Lang    string
	Surface string
	Path    string
}

LocaleFile is one locale YAML found in a directory

func ScanLocaleDir

func ScanLocaleDir(directory string) []LocaleFile

ScanLocaleDir lists every lang and surface YAML in a directory sorted by name, logging unknown surfaces

type PackEntry

type PackEntry struct {
	Lang     string
	Surface  string
	Messages map[string]string
	Source   string
	Endonym  string
	RTL      bool
	// contains filtered or unexported fields
}

PackEntry is one registered language pack layer, later registrations winning

func RegisterPack

func RegisterPack(lang, surface string, messages map[string]string, source, endonym string, rtl bool) (*PackEntry, error)

RegisterPack adds a pack layer for a language and surface and resets the facade caches

type PackInfo

type PackInfo struct {
	Endonym string
	RTL     bool
	Source  string
}

PackInfo is the newest pack metadata for a language

func PackInfoFor

func PackInfoFor(lang string) *PackInfo

PackInfoFor reports the newest pack metadata for a language, nil when no pack has it

type SecretReader

type SecretReader func(ctx context.Context, name string) (string, bool, error)

SecretReader resolves a per profile env value through the secret scope carried by ctx

Jump to

Keyboard shortcuts

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