Files
enkly-ai/pkg/i18n/embed.go
enkly 79ce8dc4c0
Some checks failed
Go CI Pipeline / build_and_test (push) Failing after 22m0s
Init Project
2026-10-30 18:06:55 +01:00

27 lines
825 B
Go

package i18n
import (
"embed"
"fmt"
)
//go:embed locales/*.json
var localeFiles embed.FS
// catalogFS is the raw JSON for each locale in Supported, read once at
// package init time (see i18n.go's init). Keeping the embed.FS read
// here, separate from the JSON-decoding in init, means adding a
// locale is purely data: list it in Supported above, drop its file
// under locales/, and this loop picks it up — no new Go code.
var catalogFS = func() map[Locale][]byte {
out := make(map[Locale][]byte, len(Supported))
for _, info := range Supported {
data, err := localeFiles.ReadFile(fmt.Sprintf("locales/%s.json", info.Code))
if err != nil {
panic(fmt.Sprintf("i18n: locale %q listed in Supported but locales/%s.json is missing: %v", info.Code, info.Code, err))
}
out[info.Code] = data
}
return out
}()