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 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 ¶
T returns the translation for key in the active locale, or key itself (the English source) when there is no non-empty translation.
func Tn ¶
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 ¶
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.