Documentation
¶
Index ¶
- Constants
- Variables
- func ClearLayerCache()
- func Flatten(node any, prefix string, out map[string]string) map[string]string
- func GetLanguage(ctx context.Context) string
- func IsLanguageID(value any) bool
- func LanguageSurfaces(ctx context.Context, h string) map[string][]string
- func LayerSurfaceCatalog(h, lang, surface string) map[string]string
- func LayeredLanguages(h string) []string
- func LoadBundled(ctx context.Context, name string) map[string]string
- func LoadLocaleSource(source any) (map[string]string, error)
- func NonTextLeaves(node any, prefix string) []string
- func NormalizeLanguageID(value any) string
- func OverlayDir(h string) string
- func OverlayLanguages(h string) []string
- func OverlayLayer(h, lang, surface string) map[string]string
- func PackLanguages() []string
- func PackLayer(lang, surface string) map[string]string
- func ParseLocaleFile(path string) (map[string]string, error)
- func ParseLocaleYAML(name string, data []byte) (map[string]string, error)
- func ResetLanguageCache()
- func ResetRegistryForTests()
- func ResolveLanguageID(ctx context.Context, value any, h string) string
- func SupportedLanguagesFor(ctx context.Context, h string) []string
- func SurfaceCatalog(ctx context.Context, lang, surface string) map[string]string
- func T(ctx context.Context, key, lang string, kwargs map[string]any) string
- func UnregisterPack(entry *PackEntry) bool
- type BundledLocales
- type LanguageOption
- type LocaleFile
- type PackEntry
- type PackInfo
Constants ¶
const ( BundledSource = "bundled" OverlaySource = "overlay" )
const CoreSurface = "core"
const DefaultLanguage = "en"
Variables ¶
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
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
var Surfaces = []string{CoreSurface, "tui"}
Functions ¶
func ClearLayerCache ¶
func ClearLayerCache()
ClearLayerCache drops merged layer views but keeps the registrations
func GetLanguage ¶
GetLanguage resolves the active language, the language setting else the default
func IsLanguageID ¶
IsLanguageID reports whether the normalized value is a language subtag with optional parts
func LanguageSurfaces ¶
LanguageSurfaces maps each language to the surfaces some layer has strings for, in Surfaces order
func LayerSurfaceCatalog ¶
LayerSurfaceCatalog merges overlay and packs for one surface, packs winning, bundled excluded
func LayeredLanguages ¶
LayeredLanguages lists languages supplied by the home overlay or any pack
func LoadBundled ¶
LoadBundled returns one bundled catalog of the profile of ctx flattened
func LoadLocaleSource ¶
LoadLocaleSource flattens a mapping source or parses a path source
func NonTextLeaves ¶
NonTextLeaves lists dotted paths of leaves that are neither text nor a mapping
func NormalizeLanguageID ¶
NormalizeLanguageID lowercases, trims and swaps underscores for hyphens, empty for non text
func OverlayDir ¶
OverlayDir is the user overlay directory of a home
func OverlayLanguages ¶
OverlayLanguages lists languages with at least one overlay file under the home
func OverlayLayer ¶
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 ParseLocaleFile ¶
ParseLocaleFile parses one locale YAML file into a flat catalog
func ParseLocaleYAML ¶
ParseLocaleYAML parses locale YAML bytes into a flat catalog, failing on a non mapping document
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 ¶
ResolveLanguageID maps a code, alias or regional tag to a supported id, empty when no layer supplies it
func SupportedLanguagesFor ¶
SupportedLanguagesFor lists every language a layer supplies for the home, en first then sorted
func SurfaceCatalog ¶
SurfaceCatalog is what a renderer receives for one surface, the core surface omitting bundled strings
func T ¶
T translates a dotted key into the explicit or active language with English then key fallback
func UnregisterPack ¶
UnregisterPack drops one registration, false when it was already gone
Types ¶
type BundledLocales ¶
BundledLocales is the bundled locale tree and the path label it is reported under
func LocalesDir ¶
func LocalesDir(ctx context.Context) BundledLocales
LocalesDir reports the bundled locale tree in effect for the profile of ctx
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 ¶
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