X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=cmd%2Fsgblog%2Fmain.go;h=a95de7a656ca31107487dff3e28eb3836429e72c;hb=bec350105fae0b0d2719a347c47929817ba57a7d;hp=767850c4b26d6ea8ce4b0b5d2d9d8990c5417582;hpb=8ec70b5cbc17244bc3627bb7a99e27b94834d419;p=sgblog.git diff --git a/cmd/sgblog/main.go b/cmd/sgblog/main.go index 767850c..a95de7a 100644 --- a/cmd/sgblog/main.go +++ b/cmd/sgblog/main.go @@ -20,9 +20,11 @@ package main import ( "crypto/sha1" + "embed" "encoding/json" "flag" "fmt" + "io/fs" "log" "os" "regexp" @@ -32,6 +34,8 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/hjson/hjson-go" + "github.com/vorlif/spreak" + "golang.org/x/text/language" ) const ( @@ -46,12 +50,18 @@ var ( commentsTree *object.Tree topicsRef *plumbing.Reference topicsTree *object.Tree + + localizer *spreak.Localizer + + //go:embed locale/* + locales embed.FS ) type Cfg struct { GitPath string Branch string Title string + Lang string URLPrefix string @@ -145,6 +155,22 @@ func readCfg(cfgPath string) (*Cfg, error) { return cfg, nil } +func initLocalizer(lang string) { + fsys, _ := fs.Sub(locales, "locale") + bundle, err := spreak.NewBundle( + spreak.WithSourceLanguage(language.English), + spreak.WithDomainFs(spreak.NoDomain, fsys), + spreak.WithLanguage(language.Russian), + ) + if err != nil { + log.Fatalln(err) + } + if lang == "" { + lang = language.English.String() + } + localizer = spreak.NewLocalizer(bundle, language.MustParse(lang)) +} + func main() { gopherCfgPath := flag.String("gopher", "", "Path to gopher-related configuration file") geminiCfgPath := flag.String("gemini", "", "Path to gemini-related configuration file")