1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-09-15 18:57:04 +00:00

Update vendor dependencies

This commit is contained in:
Frédéric Guillot 2018-07-06 21:18:14 -07:00
parent 34a3fe426b
commit 459bb4531f
747 changed files with 89857 additions and 39711 deletions

View file

@ -5,7 +5,16 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
"golang.org/x/text/message/pipeline"
"golang.org/x/tools/go/loader"
)
func init() {
@ -22,14 +31,74 @@ var cmdGenerate = &Command{
Short: "generates code to insert translated messages",
}
func runGenerate(cmd *Command, config *pipeline.Config, args []string) error {
config.Packages = args
s, err := pipeline.Extract(config)
var transRe = regexp.MustCompile(`messages\.(.*)\.json`)
func runGenerate(cmd *Command, args []string) error {
prog, err := loadPackages(&loader.Config{}, args)
if err != nil {
return wrap(err, "extraction failed")
return wrap(err, "could not load package")
}
if err := s.Import(); err != nil {
return wrap(err, "import failed")
pkgs := prog.InitialPackages()
if len(pkgs) != 1 {
return fmt.Errorf("more than one package selected: %v", pkgs)
}
return wrap(s.Generate(), "generation failed")
pkg := pkgs[0].Pkg.Name()
// TODO: add in external input. Right now we assume that all files are
// manually created and stored in the textdata directory.
// Build up index of translations and original messages.
extracted := pipeline.Locale{}
translations := []*pipeline.Locale{}
err = filepath.Walk(*dir, func(path string, f os.FileInfo, err error) error {
if err != nil {
return wrap(err, "loading data")
}
if f.IsDir() {
return nil
}
if f.Name() == extractFile {
b, err := ioutil.ReadFile(path)
if err != nil {
return wrap(err, "read file failed")
}
if err := json.Unmarshal(b, &extracted); err != nil {
return wrap(err, "unmarshal source failed")
}
return nil
}
if f.Name() == outFile {
return nil
}
if !strings.HasSuffix(path, gotextSuffix) {
return nil
}
b, err := ioutil.ReadFile(path)
if err != nil {
return wrap(err, "read file failed")
}
var locale pipeline.Locale
if err := json.Unmarshal(b, &locale); err != nil {
return wrap(err, "parsing translation file failed")
}
translations = append(translations, &locale)
return nil
})
if err != nil {
return err
}
w := os.Stdout
if *out != "" {
w, err = os.Create(*out)
if err != nil {
return wrap(err, "create file failed")
}
}
_, err = pipeline.Generate(w, pkg, &extracted, translations...)
return err
}