This repository has been archived on 2025-11-19. You can view files and clone it, but cannot push or open issues or pull requests.
Skyfeed_archive/internal/locale/loader.go

42 lines
763 B
Go

package locale
import (
"embed"
"encoding/json"
"fmt"
"path/filepath"
)
// Embed all locale JSON files inside binary
//go:embed i18n/*.json
var localeFS embed.FS
// Load all languages on startup
func LoadAll() error {
files, err := localeFS.ReadDir("i18n")
if err != nil {
return fmt.Errorf("locale: cannot read embedded FS: %w", err)
}
for _, f := range files {
name := f.Name()
path := filepath.Join("i18n", name)
data, err := localeFS.ReadFile(path)
if err != nil {
return fmt.Errorf("locale: failed to read %s: %w", name, err)
}
var b Bundle
if err := json.Unmarshal(data, &b); err != nil {
return fmt.Errorf("locale: failed to parse %s: %w", name, err)
}
lang := Lang(b.Locale)
register(lang, b)
}
return nil
}