i18n

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package i18n is a tiny gettext-style translation layer for the OpenDeezer TUI and the shared status strings served by the control API. Catalogs are flat JSON files (msgid -> translation) embedded at build time; the msgid is the exact English source string, so an untranslated key falls back to readable English automatically.

The package is a leaf (no OpenDeezer imports) so any package can call T/Tf/Tn without an import cycle. The active catalog is swapped atomically, so SetLocale is safe to call from the UI thread while other goroutines read translations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectLocale

func DetectLocale() string

DetectLocale inspects the standard locale environment variables (in POSIX precedence order) and returns the first shipped language they name, or "en".

func Locale

func Locale() string

Locale returns the active language code.

func SetLocale

func SetLocale(code string)

SetLocale switches the active catalog. code may be a bare language code ("fr") or a fuller locale ("fr_FR.UTF-8", "zh-Hans"); it is parsed down to a shipped language, falling back to English when unknown or empty.

func T

func T(key string) string

T returns the translation for key in the active locale, or key itself (the English source) when there is no non-empty translation.

func Tf

func Tf(key string, args ...any) string

Tf is T followed by fmt.Sprintf, for messages with format placeholders.

func Tn

func Tn(singular, plural string, n int, args ...any) string

Tn returns a plural-aware translation. singular is the msgid (the English singular source, e.g. "%d track"); plural is the English plural used as the fallback when the catalog has no entry. The count n is applied as the first format argument, so the placeholder for the number should come first in the template; any extra args follow.

Per-locale variants are stored under "<singular>|<category>" keys (category is one of zero/one/two/few/many/other per the CLDR cardinal rules for the locale). Missing entries fall back to the English one/other rule.

Types

type LocaleInfo

type LocaleInfo struct {
	Code string
	Name string
}

LocaleInfo is a supported language: its BCP-47-ish code and native display name.

func Available

func Available() []LocaleInfo

Available returns the shipped locales (code + native display name) in a stable order, source language first.

Jump to

Keyboard shortcuts

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